What is the best way to create a new message within a Biztalk Orchestration?

chinna picture chinna · Nov 24, 2008 · Viewed 27.5k times · Source

I'm looking for your best solutions for creating a new message instance based on a pre-defined XSD schema to be used within a Biztalk orchestration.

Extra votes go to answers with clear & efficient examples or answers with quality referenced links.

Answer

David Hall picture David Hall · Nov 24, 2008

There are several options when wanting to create a new instance of a message in a BizTalk orchestration.

I've described the three I usually end up using as well as adding some links at the bottom of the answer.

How to define which is the best method really depends - the XMLDocument method is in some regards the tidiest except that if your schema changes this can break without you knowing it. Scott Colestock describes some methods of mitigating that risk.

The BizTalk Mapping method is probably the simplest to understand and won't break when the schema changes. For small schemas this can be a good choice.

For all of these methods an important thing to remember is that if you want to use distinguished fields or promoted properties you will want to create empty elements to populate. You will hit runtime XLANG errors if you try to assign values to elements that are missing (even though those elements may be optional)

BizTalk Map

The simplest option is to just use a BizTalk map - you don't even necessarily need to map anything into the created instance.

To create empty elements you can just map in a string concatenation functoid with an empty string parameter.

Assign one message to another

If you want to create a new instance of a message you can simply copy one mesage to another message of the same schema, in a message assignment shape.

Use an XMLDocument variable

For this you create an orchestration variable of type XMLDocument and then in a message assignment use the LoadXML method to load an XML snippet that matches your schema. You then assign the XMLDocument to the desired BizTalk message.

varXMLDoc.LoadXml(@"<ns0:SomeXML><AnElementToPopulate></AnElementToPopulate></SomeXML>");  
msgYourMessage = varXMLDom;

The inclusion of AnElementToPopulate allows you to using property promotion to assign to it.

I seldom remember the syntax to do this off the top of my head, this is my go to blog entry for reminding myself of the syntax.

Another link here details some methods.