Geeks With Blogs
Bill Osuch - Random geek notes

I hadn’t intended for there to actually be a part 3 to this series, but I realized that I failed to talk about how to get the xml back into the message once you’re done messing with it. You have to convert it to a MemoryStream and assign it to IBaseMessage.BodyPart.Data, like this:

public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(Microsoft.BizTalk.Component.Interop.IPipelineContext pc, Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg)
{
    IBaseMessagePart bodyPart = inmsg.BodyPart;
    Stream originalStream = bodyPart.GetOriginalDataStream();
    if (originalStream != null)
    {
        XmlDocument myXml = new XmlDocument();
        myXml.Load(originalStream);

        myXml = DoWork(myXml); //Whatever you actually want to do to the xml

        byte[] outBytes = System.Text.Encoding.ASCII.GetBytes(myXml.OuterXml);
        MemoryStream memStream = new MemoryStream();
        memStream.Write(outBytes, 0, outBytes.Length);
        memStream.Position = 0;
        bodyPart.Data = memStream;
        pc.ResourceTracker.AddResource(memStream);
    }

    return inmsg;
}

Technorati Tags:

Posted on Thursday, January 26, 2012 11:10 AM BizTalk | Back to top


Comments on this post: Creating a custom BizTalk 2010 pipeline component–Part 3

# re: Creating a custom BizTalk 2010 pipeline component–Part 3
Requesting Gravatar...
pc.ResourceTracker.AddResource(memStream);
what is the use of this line of code...
Left by uma sankar on Nov 08, 2012 6:16 AM

# re: Creating a custom BizTalk 2010 pipeline component–Part 3
Requesting Gravatar...
Straight from Microsoft:
ResourceTracker.AddResource method is used to keep track of COM objects, Disposable objects and Streams, and should always be used inside a custom pipeline component to explicitly close (streams), dispose (IDisposable objects) or release (COM objects) these types of resources when a message is published to the BizTalk MessageBox.
Left by Bill on Nov 08, 2012 8:53 AM

Your comment:
 (will show your gravatar)


Copyright © Bill Osuch | Powered by: GeeksWithBlogs.net