Click here to Skip to main content
15,886,199 members
Articles / Programming Languages / XML
Article

How to create a self-routing message using Dynamic Ports in BizTalk Server 2004

Rate me:
Please Sign up or sign in to vote.
4.24/5 (15 votes)
1 Mar 20064 min read 103.8K   320   25   13
This article describes how to create a self-routing message using Dynamic Ports in BizTalk Server 2004.

Introduction

Consider a situation where a BizTalk message itself will have the routing information for the message. In such cases, one needs to create a Dynamic Port. In a Dynamic Port, the destination location is specified during runtime. This feature of Ports comes in very handy when one has to make routing decisions at runtime based on the content of the message.

Example - Message Segregation

A custom message "message.xsd" has the following properties:

  • ID - Holds an integer value used to categorize a message.
  • Data - The contents of the message.
  • Destination - Holds the routing information for the message.
  • Initiator - Specifies the initiator of the message.

Let us set some rules based on the "ID" property of the message.

  • All messages with ID between 200 to 299, need to be processed as High Priority messages.
  • All messages with ID between 300 to 399, need to be processed as Low Priority messages.
  • All messages with ID greater than 400 can be ignored.

Creating the BizTalk Project - "DynamicFilePorts"

Create a new BizTalk Server Project in Visual Studio .NET.

Step 1: In the Visual Studio .NET menu, select File -> New -> Project, and type the name "DynamicFilePorts".

NewProjectDialog

Building the Schemas

Step 2: Right-click on the project in the Solution Explorer, and select the "Add New Item" option. Then, select the item "Schema" and name it "Message". When the schema shows up, rename the "Root" element to "Message". After that, create the child elements: "ID", "Data", "Destination" and "Initiator".

Message Schema Elements

Element NameElement Type
IDxs:int
Dataxs:string
Destinationxs:string
Initiatorxs:string

Please refer to the image below and confirm your schema file...

MessageSchema

Building the Orchestration (also known as a "Business Process")

This Orchestration would have just three shapes, a Receive shape, an Expression shape, and a Send shape.

Step 3: Right-click on the project in the Solution Explorer, and select the "Add New Item" option. Then, select the item "BizTalk Orchestration" and name it "DynamicPortsDemo".

DP_Orchestration

Step 4: Place the three shapes on the "Orchestration Surface".

  1. Receive shape
  2. Expression shape
  3. Send shape

Step 5: Create a message.

  1. In the Orchestration View, right-click on the Messages folder, and select "New Message". Rename it as "IncomingMessage", and in the Properties window, set the Message Type as "DynamicFilePorts.Message".

Step 6: Setting Properties for all the shapes.

  1. Select the Receive shape, and in the Properties window, set the Message Type as "IncomingMessage", and set the property "Activate" as True.
  2. Select the Send shape, and in the Properties window, set the Message Type as "IncomingMessage".
  3. Select the Expression shape, double-click, and type the code shown below...

BizTalkExpressionEditor

C#
// Instantly process the message.
if (IncomingMessage.ID >= 200 && IncomingMessage.ID <= 299)
{
  OutputDataPort(Microsoft.XLANGs.BaseTypes.Address) = 
      "FILE://C:/BiztalkProjects/DynamicFilePorts/" + 
      IncomingMessage.Destination + 
      "/HighPriorityMessage_%MessageID%.xml";
}
// Low Priority message processing.
else if (IncomingMessage.ID >= 300 && 
         IncomingMessage.ID <= 399)
{
  OutputDataPort(Microsoft.XLANGs.BaseTypes.Address) = 
      "FILE://C:/BiztalkProjects/DynamicFilePorts/" + 
      IncomingMessage.Destination + 
      "/LowPriorityMessage_%MessageID%.xml";
}
// Ignore this message.
else
{
  OutputDataPort(Microsoft.XLANGs.BaseTypes.Address) = 
     "FILE://C:/BiztalkProjects/DynamicFilePorts/" + 
     IncomingMessage.Destination + 
     "/IgnoreMessage_%MessageID%.xml";
}

Step 7: Create two Ports (a Receive port and a Send port)

  1. Receive port - Right-click on the Port Surface, and select "New Configured Port", and set the Name as "InputDataPort", leave all the default properties as it is in the Wizard.
  2. Send Port - Right-click on the Port Surface, and select "New Configured Port", and set Name as "OutputDataPort", set the remaining properties as shown in the image below...

PortConfiguration

Step 8: Strong name and deployment!!

  1. Create a key file using "sn -k Dynamic.snk" in the Visual Studio .NET command prompt.
  2. In the Solution Explorer, right-click on the "DynamicFilePorts" Project Properties, and select "Assembly" and specify the key file name.

    StrongName

  3. In the Solution Explorer, right-click on the "DynamicFilePorts" Project Properties and select "Deploy".
  4. 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.

    BindingProperties

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

Step 9: Refresh BizTalk Explorer and create Receive Location.

  1. Please refer to the MSDN documentation on how to create a Send Port and Receive Locations.

Step 10: Test the Solution

  1. Create the folders "InputFiles", "InstantProcessing", "LowPriority", and "Ignore" under any directory. Place the input file in the Receive Location. Check the response in any of the folders based on the input message.
  2. Note that the input file is routed to the destination folder according to the "ID" of the message.

Quick Takeaways

  1. Always set the Activate property to "True" for the first Receive Shape in the orchestration.
  2. Note the use of if-else conditions used directly in the "Expression" shape, instead of using a "Decide" shape.
  3. Content based routing can also be done using filters in Send Ports.
  4. A BizTalk service needs to be re-started every time a deployment is done.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect AT&T Wi-Fi Services
United States United States
Naveen has done his Masters (M.S.) in Computer science, has started his career programming the mainframes and now has more than a decade of programming, development and design experience. Naveen has a sharp eye and keen observation skills. Naveen has worked for several companies and strived hard to build large scale business applications and bringing better solutions to the table.
Quite recently Naveen has built a fairly complex integration platform for a large bank. His hobbies include training, mentoring and research. Naveen spends his free time visiting National Parks nationwide.

Naveen has developed the BizTalk Control Center (BCC)
http://biztalkcontrolcenter.codeplex.com

Comments and Discussions

 
GeneralNetwork URL path in dynamic port Pin
harishusharma29-Jun-09 1:32
harishusharma29-Jun-09 1:32 
AnswerRe: Network URL path in dynamic port Pin
harishusharma29-Jun-09 4:32
harishusharma29-Jun-09 4:32 
AnswerVarious Dynamic port configurations Pin
Naveen Karamchetti24-Mar-09 10:09
professionalNaveen Karamchetti24-Mar-09 10:09 
QuestionHow to create Dynamic send port for MS CRM 3.0/4.0 in BizTalk 2006 Pin
kuldip0122-Dec-08 0:24
kuldip0122-Dec-08 0:24 
AnswerRe: How to create Dynamic send port for MS CRM 3.0/4.0 in BizTalk 2006 Pin
Naveen Karamchetti24-Mar-09 12:27
professionalNaveen Karamchetti24-Mar-09 12:27 
This is what you would need to do...

Add the Dynamics CRM Property Schema 'PropertySchema.xsd'. Locate this schema in the Microsoft CRM Dynamics BizTalk Adapter installation folder

C:\Program Files\[CRM Adapter installation folder]\Schemas

Set the following properties in the orchestration

CrmQueryRequest(PropertySchema.ServerUrl) = "http:/server_name/MSCRMServices/2006/";
CrmQueryRequest(PropertySchema.UserName) = @"domain-name\user-name";
CrmQueryRequest(PropertySchema.Password) = @"p@ssword";

CRMQueryPort(Microsoft.XLANGs.BaseTypes.Address)="http:/server_name/MSCRMServices/2006/";
// The name of the adapter listed in the BizTalk administration console
CRMQueryPort(Microsoft.XLANGs.BaseTypes.TransportType) = "Microsoft Dynamics CRM";

Always be there....| MCSD.NET | Sun Certified...

QuestionHow to call web service by dynamic port in biztalk 2006 Pin
RyanElee27-Aug-07 16:59
RyanElee27-Aug-07 16:59 
QuestionSetting the Address property Pin
GunnerOlesen11-Feb-07 8:40
GunnerOlesen11-Feb-07 8:40 
AnswerRe: Setting the Address property Pin
GunnerOlesen11-Feb-07 9:59
GunnerOlesen11-Feb-07 9:59 
QuestionWhat about other transport types? Pin
WillemM20-Oct-06 0:10
WillemM20-Oct-06 0:10 
AnswerRe: What about other transport types? Pin
WillemM20-Oct-06 1:07
WillemM20-Oct-06 1:07 
GeneralHard coded target path not usefull Pin
benjamin wegner7-Mar-06 20:27
benjamin wegner7-Mar-06 20:27 
GeneralRe: Hard coded target path not usefull Pin
TeddyBeer7-Mar-06 22:30
TeddyBeer7-Mar-06 22:30 
GeneralRe: Hard coded target path not usefull Pin
_ABHILASH_MS_22-Mar-06 0:21
_ABHILASH_MS_22-Mar-06 0:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.