How to publish an XmlDocument or Microsoft.XLANGs.BaseTypes.Any message to the MessageBox with its MessageType promoted!

Sometimes you would like to have a generic orchestration that can handle any type of messages that should be send to the MessageBox through a direct bound send port. Ofcourse it would be nice if the message could be routed based on its MessageType after being published. Unfortunately when publishing an XmlDocument or Any message from an orchestration the message type is not promted. Also it can’t be promoted from within the orchestration because BTS.MessageType is read-only.

A solution for this problem was on my wish list for a while and finally I found one.

It’s a combination of calling the XMLReceive pipeline inside the orchestration and assigning an initializing correlation set with the BTS.MessageType to the send shape. The XMLReceive pipeline determines the message type and the correlation set promotes it.

First ad the following references to the orchestrations project:


Within a scope with atomic transaction type create a variable of .Net type Microsoft.XLANGs.Pipeline.ReceivePipelineOutputMessages. Use an assignment shape to assign the XMLDocument or Any body part of the message and execute the XMLReceive pipeline. For example:

msgRetry.HeaderPart = varHeader;
msgRetry.BodyPart = xpath(msgFault, "/*[local-name()='FaultMessage' and namespace-uri()='']/*[local-name()='Messages' and namespace-uri()='']/*[local-name()='Message' and namespace-uri()='' ][MessageName='BodyPart']/*[local-name()='MessageData' and namespace-uri()='']/*/*");

varPipelineMessages = Microsoft.XLANGs.Pipeline.XLANGPipelineManager.ExecuteReceivePipeline(typeof(Microsoft.BizTalk.DefaultPipelines.XMLReceive), msgRetry);


Next a correlation type is needed with BTS.MessageType as correlation property. An initializing correlation set of this type needs to be assigned to the direct bound send port.

The atomic scope is needed because the ReceivePipelineOutputMessages type is not serializable. This could be avoided by wrapping the pipeline code in an external static helper method like this:

public static void DetermineMessageType(XLANGMessage message)
	ReceivePipelineOutputMessages pipelineMessages = XLANGPipelineManager.ExecuteReceivePipeline(typeof(Microsoft.BizTalk.DefaultPipelines.XMLReceive), message); 


2 Responses to How to publish an XmlDocument or Microsoft.XLANGs.BaseTypes.Any message to the MessageBox with its MessageType promoted!

  1. Dima says:

    This helped me today in BizTalk 2010 project. Strange thing I have another project on 2006 R2 where BTS.MessageType gets promoted automatically on XmlDocument. Strange..

  2. Junaid says:

    Absolute life saver . . . thanks a ton !!!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: