Thursday, March 3, 2011

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

Hi there,

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.

From stackoverflow
  • What exactly are you looking for? Is it just creating a new message with a fixed content (like a sort of template)? Or based on something else? You really need to clarify the question and be more specific to get a proper answer.

    If you're referring to just creating a message from scratch based with sort of hardcoded content (or close to), then I've found that putting them as embedded resources in a helper C# assembly to be a pretty clean way of doing it. Scott Colestock has a pretty good explanation of this technique.

  • To create a new message you can simply create a new System.Xml.XmlDocument and assign that to a message variable. You can use it's Load or LoadXml methods to load the required content that conforms to the schema.

  • 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 of 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.

  • This tutorial may be of some help:

    BizTalk Server 2006 Tutorial - A Walk Through the Process Creating services with contract-first design using BizTalk Server 2006 R2 and Windows Communication Foundation

    http://dotnet.sys-con.com/node/647092

    SteveC : Nice walk-through article
  • Check out my blog post - Fun with Message Creation in BizTalk - for a basic performance comparison between various options.

0 comments:

Post a Comment