Ayman’s BizTalk Lab

November 19, 2007

BizTalk 2006 CV Management Application by Mail (Part 2)

Filed under: Uncategorized — Admin @ 11:52 am
Tags: , , ,

Hello Again, as I didn’t have enough time to complete the previous post and didn’t find it suitable to make this topic in one big post; Here we are back again to complete our solution.

In the previous part we built our orchestration and our output was a multi-part message that will be send through dynamic port with SMTP adapter.

As you may remember we had a requirement to send the Employee Data part of the message as an InfoPath form. InfoPath form are normal XML files with special Processing Instruction to define the template of the form and to declare that this XML file is an InfoPath form.

a typical InfoPath processing Instruction may look like this :

<?mso-infoPathSolution solutionVersion=”″ productVersion=”11.0.5531″ PIVersion=”″ href=”file:///D:\BTSCvWorkflow\EmpData.xsn” language=”ar-eg” ?>
<?mso-application progid=”InfoPath.Document”?>

and to get this PIs, simply open your InfoPath form in Notepad. so we simply want to make an InfoPath form template that has 5 fields as shown in the picture:

BTS-002 BTS-003
Form fields Data source

one way to inject the PIs is simply in a construct message shape we can do the following :

MsgOutput(XMLNORM.ProcessingInstruction)=”<?mso-infoPathSolution solutionVersion=\”\” productVersion=\”11.0.5531\” PIVersion=\”\” href=\”file:///D:\\BTSCvWorkflow\\EmpData.xsn\” language=\”ar-sa\” ?><?mso-application progid=\”InfoPath.Document\”?>”;

Note: don’t forget to escape the quotes ”

but this solution is not applicable in our case cause as soon we assign the message we have just constructed to another message the orchestration removes the PIs. and we had to do this assignment cause as you remember we had a multi-part message constructed from three message parts and we only want to add the PIs to the XML part of the Multi-Part message.

it’s kind complicated but I hope you got the idea, so another proposed solution seemed suitable and that we have to create a custom send pipeline component in the decode stage to manipulate the message and inject the PIs in the EmpData part of the message.

so, I used the nice Pipeline Component Wizard tool which you can get from here to generate the base code for our send pipeline component which will reside in the Encode phase..

basically our code for the pipeline will reside in the Execute method. so what we will do in the Execute Method :

  1. we will define an XmlDocument object to carry the EmpData part of our output message.
  2. define two XmlProcessingInstruction objects for the PIs we have. and then add the two objects the the XmlDocument object.
  3. we then need to define a MemoryStream object and save the XmlDocument in it.
  4. then we have to replace the stream that fills the EmpData part of the message with the MemoryStream we have just created. and don’t forget to add the stream to the ResourceTracker to keep and dispose it when it finishes.
  5. the last step is to return the message.

the will be something like this:

XmlDocument doc = new XmlDocument();
XmlElement docelem = doc.DocumentElement;
XmlProcessingInstruction pi1 = doc.CreateProcessingInstruction(
“mso-infoPathSolution”, “solutionVersion=\”\” productVersion=\”11.0.5531\” PIVersion=\”\” href=\”file:///D:\\BTSCvWorkflow\\EmpData.xsn\” language=\”ar-eg\””);
XmlProcessingInstruction pi2 = doc.CreateProcessingInstruction(“mso-application”, “progid=\”InfoPath.Document\””);

doc.InsertBefore(pi1, docelem);
doc.InsertAfter(pi2, pi1);
Stream memstream = new MemoryStream();
memstream.Seek(0, SeekOrigin.Begin);
inmsg.GetPart(“EmpData”).Data = memstream; pc.ResourceTracker.AddResource(memstream);
return inmsg;

So we ill build our component, copy the dll to “C:\Program Files\Microsoft BizTalk Server 2006\Pipeline Components” if you have have BizTalk installed in the default directory. and then add a new Send pipeline to our BizTalk project then add our component to the toolbox from (Tools -> Chose Toolbox Items) then from the BizTalk Pipeline Components tab we select our Pipeline which will appear there by now.

then we simply drag the new added component to the Encode Phase as shown in the figure:


And that’s it, we build, we deploy the we will administrate 🙂

we have to create the physical ports for our application and I guess this is the easy part but don’t forget to set the pipeline for the send port to our custom one.

there still another step we didn’t talk about which is an ASP.NET page to be the front end for our application. we will leave this page to another time.

have fun 🙂

to be continued …

see you in the next post.


1 Comment »

  1. Loved the post ..

    Keep it up

    Comment by Ahmed Farrag — December 1, 2007 @ 12:10 am | Reply

RSS feed for comments on this post. TrackBack URI

Leave a Reply

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

WordPress.com Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

Blog at WordPress.com.

%d bloggers like this: