dcsimg
November 22, 2017
Hot Topics:

Custom Pipeline Component for the DB2 Adapter

  • November 2, 2007
  • By Drew Block
  • Send Email »
  • More Articles »

One of the things that I find most enjoyable about BizTalk is the ability to interface with so many different types of systems. With this ability, there always hurdles in getting these systems to work well with each other.

Recently, I developed an integration from DB2 to MS CRM. One of the challenges was pulling the XML from the adapter into BizTalk. The adapter's setup is very similar to the SQL adapter, but the resulting XML could not be translated by BizTalk. To bring in the XML, white spacing, encoding, as well as namespaces had to be updated.

Create the Pipeline Custom Component

The first step was to create a new custom pipeline component that would be put into the receive pipeline of the inbound DB2 record.I used a Decode component for this task. For the Decode component, I had the class inherit IBaseComponent, IComponentUI, and IComponent.



Click here for a larger image.

IBaseComponent

There are three properties needed for inheritance: Name, Description, and Version.

[Browsable(false)]
public string Description
{
   get
   {
      return "Component to format DB2 XML for contacts";
   }
}

[Browsable(false)]
public string Name
{
   get
   {
      return "DB2 Contact Formatter";
   }
}

[Browsable(false)]
public string Version
{
   get
   {
      return "1.0.0.0";
   }
}

IComponentUI

The IComponentUI properties are used within the Editor. There are two required properties.

#region IComponentUI

[Browsable(false)]
public IntPtr Icon
{
   get { return IntPtr.Zero; }
}

public System.Collections.IEnumerator Validate(object obj)
{
   return null;
}
#endregion

IComponent

The main processing will be done in the IComponent. You will override the Execute method to modify the inbound XML into a value that BizTalk can accept.

As you step through the execute method, the first task is to capture the inbound document, which is part of the inbound message. Here, you put it into a Stream so that you can translate it easily. From the Stream, you then read the stream value into a string utilizing the Unicode encoding.

The following section manipulates the data. In my usage with the DB2 adapter, the first character was always a space, so I strip that off. I replace the nodes with the namespace info property for self subscribing. Afterwards, I write out the value as a UTF8-encoded string for BizTalk to evaluate.

#region IComponent

public IBaseMessage Execute(IPipelineContext pc, IBaseMessage inmsg)
{
   string originalDataString = string.Empty;

   try
   {
      Stream originalMessageStream =
         inmsg.BodyPart.GetOriginalDataStream();
      byte[] bufferOriginalMessage =
         new byte[originalMessageStream.Length];

      originalMessageStream.Read(bufferOriginalMessage, 0,
         Convert.ToInt32(originalMessageStream.Length));

      originalDataString =
         System.Text.UnicodeEncoding.Unicode.
         GetString(bufferOriginalMessage);

   }
   catch (Exception ex)
   {
      throw new ApplicationException("Error in reading original
         message: " + ex.Message);
   }

   string temp = string.Empty;
   try
   {
      originalDataString = originalDataString.Substring(1);

      temp = originalDataString.Replace("xmlns=\
         "http://DB2ReceiveContact\"",
         "xmlns:ns0=\"http://DB2ReceiveContact\"");
      temp = temp.Replace("<?xml version=\"1.0\"?>",
         "<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
      temp = temp.Replace("DB2Contact", "ns0:DB2Contact");
      temp = temp.Replace("><FT112", "> <ns0:FT112");
   }
   catch (System.Exception ex)
   {
      throw new ApplicationException("Error executing pipeline: "
         + ex.Message);
   }


      byte[] bufferOoutgoingMessage =
         System.Text.ASCIIEncoding.ASCII.GetBytes(temp);
      inmsg.BodyPart.Data =
         new MemoryStream(bufferOoutgoingMessage);


      return inmsg;
   }
#endregion




Page 1 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date