Stephen Kaufman's WebLog

Look who's BizTalk'in - Notes on all things integration

Accessing Promoted Properties in a Pipeline Component

Accessing Promoted Properties in a Pipeline Component

Rate This
  • Comments 2

You can get access to any promoted properties that exist in the property schema for a specific message type.  I was on a project where we were trying to send data to a stored procedure on an Oracle database.  We created a property schema to promote the fields that we needed and created a custom pipeline component which would access these promoted properties through the context object.  This is certainly not the only way to solve the problem but for this project I only needed a messaging solution.  In addition by utilizing this solution I did not need to instantiate another instance of the DOM but instead utilized the results from the DOM that was used in BizTalk.

 

In order to do create this scenario create 2 projects.  The first will be the BizTalk project and the second will be for the custom pipeline component.  follow these steps:

 

BizTalk Project:

  1. Create the source and destination schema
  2. Create a map
  3. Create a property schema (or have it created for you by doing a quick promotion from your schema)
  4. Set the Property Schema Base property attribute to MessageContextPropertyBase for each promoted element
  5. Create a Pipeline (.btp) and place the custom pipeline created in the steps below along with the XML Assember.  Make sure to specify the schema for the Assembler

 

Custom Pipeline Project:

  1. Create a custom pipeline component project (you can do this either from a sample in the SDK such at the FixMsg or by having your class inherit from these interfaces; IBaseComponent, Microsoft.BizTalk.Component.Interop.IComponent, Microsoft.BizTalk.Component.Interop.IPersistPropertyBag and IComponentUI)
  2. Add a reference to the Microsoft.BizTalk.Pipeline dll located in the Program Files\Microsoft BizTalk Server 2004 directory.
  3. Add methods to implement those required from the interfaces
  4. When you implement the Execute Method,

The method signature will look like:

public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)

{

 

}

There are two contexts that are available; the Pipeline context and the context of the IBaseMessage.  It is the IBaseMessage context that we want to get access to.

 

  1. To get access, create a variable of type IBaseMessageContext and assign it the context.

IBaseMessageContext context = pInMsg.Context;

 

  1. We now need to call the Read method.  The read method takes 2 strings as input.  The first is the name of the promoted property as it exists in the property schema.  The second is the fully qualified namespace of the property schema.  The method returns an object which will contain the value of the promoted type.  Since this is an object type you will need to appropriately cast this to the datatype of the promoted property. 

    Add the following line

 

          object obj = context.Read("Facility", "http://XMLPipeBTS.PropertySchema");

 

  1. We now have access to the value that was promoted.  At this point we can do things like send this data to a database or a custom logging or tracking system  Also remember that we still have to pass back a message.  In this case I am just passing back what was passed in.

 

         The full method looks like this:

 

public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)

{

IBaseMessageContext context = pInMsg.Context;

 

object obj = context.Read("Facility", "http://XMLPipeBTS.PropertySchema");

if (null != obj)

{

// do some work with each value that was promoted

}

return pInMsg;

}

 

If there are problems accessing your promoted properties there are a couple of places that you can check to see if they are accessible by the system. 

 

The first place is on the send port.  If you select the filter section you should see your promoted item in the drop down list box under the property section. 

 

The second is in HAT.  Change the configuration so that a message gets suspended (such as stopping the send port).  Click on the Operations menu and then the Messages menu.  Click the Run Query button and find your message, right click on the message and select Message Details from the pop up menu.  When the dialog box appears there will be a context item.  Click on the ellipsis and another dialog box will appear that will show all of the context properties that accompany the message (including the namespace).

Page 1 of 1 (2 items)