65.9K
CodeProject is changing. Read more.
Home

Configuring BizTalk Orchestrations to handle un-typed messages

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.29/5 (11 votes)

Mar 2, 2006

CPOL

3 min read

viewsIcon

69143

downloadIcon

606

This article describes how to create/handle un-typed messages in BizTalk Server 2004 orchestrations.

Introduction

A typical orchestration in BizTalk deals with several kinds of messages. A message in BizTalk is always strongly typed. It is usually associated to some schema defined in the project. A Receive/Send shape in an orchestration is tied to a message declared in the Orchestration View. In the case of an un-typed message, the message type is set to 'System.Xml.XmlDocument', instead of a schema type. The class "XmlDocument" is a super class for all XML messages, and hence it can hold any type of XML message and subsequently any type of orchestration message. To summarize, an un-typed message is one whose message type is set to "XmlDocument" in an orchestration.

Example - processing un-typed messages

Consider that we are integrating several small messages into a StoreFront application. This application deals with several kinds of messages like "Car", "Music" and "Book". These messages need to be integrated into a "StoreFront" message. So, a designed orchestration would receive several different types of messages. The orchestration in the article is shown below:

In the above orchestration, the "Send" and "Receive" shapes can handle any type of message. It is because the "Receive" shape is associated with a message which is of type "XmlDocument".

The Decision shape separates out the different kinds of messages.

// Message Type consists of TargetNamespace#SchemaRootElementName
InputMessage(BTS.MessageType) == 
       "http://UntypedMessages.Book#BookMessage"

// Message Type consists of TargetNamespace#SchemaRootElementName
InputMessage(BTS.MessageType) == 
       "http://UntypedMessages.Car#CarMessage"

// Message Type consists of TargetNamespace#SchemaRootElementName
InputMessage(BTS.MessageType) == 
       "http://UntypedMessages.Music#MusicMessage"

Notice the commonality in the above schemas. A quick explanation of one of the schemas is as follows:

The schema "Car.xsd" has the following properties:

  • RegID - The registration ID.
  • Make - The make of the car.
  • Model - The year of manufacture.
  • Operation - Can be either "BUY" or "SELL".
  • ExpectedPrice - The expected price.

The "InputMessage" message is specified in the Receive shape:

The "OutputMessage" message is specified in the Send shape:

The Message Assignment shape has the following lines of code:

BookMsg = InputMessage;
regId = BookMsg.RegID;
category = "BOOK";
operation = BookMsg.Operation;
dataItem1 = BookMsg.Author;
dataItem2 = BookMsg.Pages;
expectedPrice = BookMsg.ExpectedPrice;

xmlDocument = new System.Xml.XmlDocument();  
xmlDocument.LoadXml("<ns0:StoreFront " + 
     "xmlns:ns0='http://UntypedMessages.StoreFront'><RegID>"+
 regId +"</RegID><Category>"+ 
 category +"</Category><ExpectedPrice>"+ 
 expectedPrice +"</ExpectedPrice><DataItem1>"+ 
 dataItem1 +"</DataItem1><DataItem2>"+ 
 dataItem2 +"</DataItem2><Operation>"+ 
 operation +"</Operation></ns0:StoreFront>");

OutputMessage = xmlDocument;

Line 1: The InputMessage is assigned to BookMsg, so as to retrieve its promoted properties.

Line 2-7: Retrieving the promoted properties of the BookMsg.

Line 8: Creating an instance of 'xmlDocument' and loading the XML for output.

Line 10: Assigning 'xmlDocument' variable to OutputMessage. This OutputMessage shall be sent through the "Send" port.

Strong name and deployment!!

  1. Create a key file, using the "sn -k Untyped.snk", in the Visual Studio .NET command prompt.
  2. In the Solution Explorer, right-click on the "UntypedMessages" project properties and select "Assembly" and specify the key file name.
  3. In the Solution Explorer, right-click on the "UntypedMessages" project properties and select "Deploy".

Download and test the solution

  1. Download the zip file and extract the source code provided into any directory of your choice. Look into the folder "InputFiles" for sample input XML files. Place the input file in the receive location. Check the response in the "Out" folder based on the input message.
  2. In the BizTalk Explorer, right-click on the listed orchestration under the "Orchestration" folder and select "Bind...". Create a receive port and a receive location:

    In the BizTalk Explorer, right-click on the listed orchestration under the "Orchestration" folder and select "Start". The orchestration icon must turn to blue.

Quick takeaways

  1. Always set the Activate property to "true" for the first Receive shape in the orchestration.
  2. The "Terminate" shape is required in the orchestration, without which the project will not compile, since that particular branch does not generate any outgoing message.
  3. A BizTalk service needs to be re-started every time a deployment is done.