Simplified BizTalk Content Based Routing for a Passthrough data

 I had simple task, I had image files that need to be routed (“copied”) to another location based on some field being set inside the image metadata. I devised a simple solution that consists of a simple pipeline component that promotes the filed into the Message Context, create a dummy schema with promoted field. Use the pipeline component in a custom pipeline. This solution would read the information and promote the field values if they exist without publishing the whole image into the message box database. Delivering performance similar to using the standard pass-throu pipeline. Bellow you can find the pipeline and the sample code of the component


/// Implements IComponent.Execute method.


<param name=”pc”>Pipeline context</param>

<param name=”inmsg”>Input message.</param>

<returns>Processed input message with appended or prepended data.</returns>


/// IComponent.Execute method is used to initiate

/// the processing of the message in pipeline component.


IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)




IBaseMessagePart bodyPart = pInMsg.BodyPart;

string imgsrc = null;

if (bodyPart != null)


Stream srcs = bodyPart.GetOriginalDataStream();

StreamReader tr = new

string contents;

string beginCapture = “<photoshop:Source>”;

string endCapture = “</photoshop:Source>”;

int beginPos;

int endPos;

contents = tr.ReadToEnd();

Debug.Write(contents.Length + ” chars” + Environment.NewLine);

beginPos = contents.IndexOf(beginCapture, 0);

if (beginPos > 0)


endPos = contents.IndexOf(endCapture, 0);

Debug.Write(“xml found at pos: “ + beginPos.ToString() + ” – “ + endPos.ToString());

imgsrc = contents.Substring(beginPos + beginCapture.Length + 1, (endPos – (beginPos + beginCapture.Length + 1)));

Debug.Write(“Xml len: “ + imgsrc.Length.ToString() + ” Imgsrc = “ + imgsrc);


// return the cursor to the start of the stream

srcs.Seek(0, SeekOrigin.Begin);


pInMsg.Context.Promote(“Source”, @”http://MoustafaRefaat.ImagingPipeLine.PropertySchema.PropertySchema&#8221;, imgsrc);


catch (Exception ex)




return pInMsg;


If you have any questions I would love to hear from you

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 )

Facebook photo

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

Connecting to %s

%d bloggers like this: