Creating a custom BizTalk 2010 pipeline component–Part 2

In the last post I showed how to create the skeleton of a pipeline components, add it to the toolbox, integrate it into a BizTalk app and deploy & test it. This time I’ll go over working with the XML, reading and writing message context properties, and reading and writing custom component properties.

To get the xml portion of the message, you can get a Stream from IBaseMessage.Body.Part.GetOriginalDataStream and load it into an XmlDocument. In our case we’re manipulating the structure of an 837 HIPAA claim, so I’m not going to going into all the details, but here’s a method to write the xml out to a file:

protected void WriteXmlToFile(IBaseMessage message, string fileName) {     IBaseMessagePart bodyPart = message.BodyPart;     Stream originalStream = bodyPart.GetOriginalDataStream;     XmlDocument xdoc = new XmlDocument;     xdoc.Load(originalStream);     xdoc.Save(fileName); }

You can read the various message context properties (see this link for a list) by querying IBaseMessage.Context, like this:

protected void ReadContextProperties(IBaseMessage message) {     string inboundTransportType = (string)message.Context.Read("InboundTransportType", "http://schemas.microsoft.com/BizTalk/2003/system-properties");     string receivedFileName = (string)message.Context.Read("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties");     string interchangeID = (string)message.Context.Read("InterchangeID", "http://schemas.microsoft.com/BizTalk/2003/system-properties"); }

You can write (update) context properties with IBaseMessage.Context.Write:

protected void WriteContextPropertyValue(IBaseMessage message, string propertyName, string propertyNamespace, string propertyValue) {     message.Context.Write(propertyName, propertyNamespace, propertyValue); }

Reading custom properties is done in the Load method that was automatically generated by the Pipeline Component Wizard. In the last post I created a property called “TestProperty”, and this is the code that was created:

public virtual void Load(Microsoft.BizTalk.Component.Interop.IPropertyBag pb, int errlog) {     object val = null;     val = this.ReadPropertyBag(pb, "TestProperty");     if ((val!= null))     {         this._TestProperty = ((string)(val));     } }

So, tying this all together in the Execute method would look something like this:

public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(Microsoft.BizTalk.Component.Interop.IPipelineContext pc, Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg) {     WriteXmlToFile(inmsg, _TestProperty);

    ReadContextProperties(inmsg);

    WriteContextPropertyValue(inmsg, "ReceivedFileName", ", "NewFileName");

   return inmsg; }

Technorati Tags:

This article is part of the GWB Archives. Original Author: Bill Osuch

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.