James Mann's Blog

The blog of James Mann

Creating Multiple Messages in a BizTalk Server disassemble pipeline component

There is a interface IBaseMessageFactory that you can use to create instances of BizTalk messages and BizTalk message parts.

You can grab a handle to an instance of a subtype of this interface from within the Dissassemble method using the IPipelineContext.GetMessageFactory().

An important thing to note is that in order to preserve the message context you must grab this from the original message and poke it into the new instances created by the factory. The following code illustrates it.

public void Disassemble(Microsoft.BizTalk.Component.Interop.IPipelineContext pc, Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg)
{
IBaseMessageContext sourceContext = inmsg.Context;
IBaseMessagePart part = inmsg.BodyPart;

// queue four messages to be processed in the GetNext() method.
// _msgs is a simple Queue
_msgs.Enqueue(CreateMessage(pc, sourceContext,part));
_msgs.Enqueue(CreateMessage(pc, sourceContext,part));
_msgs.Enqueue(CreateMessage(pc, sourceContext,part));
_msgs.Enqueue(CreateMessage(pc, sourceContext,part));
}

private string messageType = @"http://www.myschema.com/schemas/myschemamessage/MySchema";
private string systemPropertiesNamespace = @"http://schemas.microsoft.com/BizTalk/2003/system-properties";

public IBaseMessage CreateMessage(IPipelineContext pc, IBaseMessageContext sourceContext, IBaseMessagePart part)
{
IBaseMessage msg = pc.GetMessageFactory().CreateMessage();
msg.AddPart("Body", part, true);


// comment out the following line to preserve the original message
msg.BodyPart.Data = new MemoryStream(ASCIIEncoding.ASCII.GetBytes("blah blah blah"));
msg.Context = sourceContext;
msg.Context.Promote("MessageType", systemPropertiesNamespace, messageType);
return msg;
}

Comments (2) -

  • Steve

    11/30/2007 9:35:23 PM |

    I have a question. I am doing something similar, but something weird happens. The messages are built in the Disassemble method. I add them to a queue just the same, then inside of GetNext the code looks like this:


    if (_msgs.Count > 0)


     return (IBaseMessage)qOutputMsgs.Dequeue();


    else


     return null;


    Sometimes it works, and the pipeline returns me the messages I built, but other times it does not; it goes into GetNext tries to return the first message and then it stops, and the message never gets retrieved from the receive location nor put in the message box. Have you any suggestion as to what could be the problem.


    Thanks

  • Reviews on Hypothyroidism Revolution

    10/30/2013 9:55:33 PM |

    I was recommended this web site by my cousin. I am not sure whether this post is written by him as no one else know such detailed about my trouble. You are wonderful! Thanks!

    Also visit my web-site;  Reviews on Hypothyroidism Revolution - http://hypothyroidismrevolutionreview.tumblr.com

  • Arab Voyeur

    11/9/2013 2:35:16 PM |

    We are a gaggle of volunteers and opening a brand new scheme in our community. Your web site provided us with valuable info to work on. You've performed a formidable job and our entire group will be grateful to you.

    My homepage;  Arab Voyeur - http://imc.ichiayi.com/userinfo.php?uid=38329

  • Blondes Grannies

    11/22/2013 6:04:19 PM |

    Nice post. I learn something totally new and challenging on sites I stumbleupon everyday. It will always be helpful to read through articles from other writers and use a little something from other websites.

    Visit my web page  Blondes Grannies - http://nxnn.info/user/SilviaFul

  • Water Softener Installation

    1/3/2014 1:43:48 PM |

    Hello, I enjoy reading all of your article post. I wanted to write a little comment to support you.|

  • Restaurant Equipment

    1/5/2014 2:11:51 PM |

    Hey there! I simply want to offer you a big thumbs up for your excellent information you have here on this post. I am returning to your website for more soon.|

  • Denny Bungard

    1/20/2014 6:24:51 PM |

    obama is cool

  • Denny Bungard

    1/20/2014 7:00:35 PM |

    thanks for posting the link to vip xxx

Loading