Click here to Skip to main content
Email Password   helpLost your password?

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:

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

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 Name Element Type
ID xs:int
Data xs:string
Destination xs:string
Initiator xs: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

// 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.
You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralNetwork URL path in dynamic port
harishusharma
2:32 29 Jun '09  
Hello Naveen,

Can we use network url path while setting dynamic port in BTS 2006.
Say, i have another pc in my network which i access thro' \\192.168.12.15\SomeFolder

I tried with setting
"file://\\192.168.12.15\SomeFolder\filename.txt"

I received the following error after executing the component.
Error details: The FILE send adapter cannot open file \\192.168.12.15\SomeFolder\filename.txt for writing.
Details: Logon failure: unknown user name or bad password.

Q: how to set the username and password and where ?

any help is highly appreciable.
thanx a tonne in advance.
harry
AnswerRe: Network URL path in dynamic port
harishusharma
5:32 29 Jun '09  
Got the answer. just need to set the properties of output message and assign it to the send port

thanx anyways
AnswerVarious Dynamic port configurations
Naveen Karamchetti
11:09 24 Mar '09  
Various dynamic port configurations

DynamicSendPort(Microsoft.XLANGs.BaseTypes.Address)="mailto:johnd@contoso.com";

DynamicSendPort(Microsoft.XLANGs.BaseTypes.Address)=@"file://C:\MyLocation\%SourceFileName%.xml";

DynamicSendPort(Microsoft.XLANGs.BaseTypes.Address)=@"msmq://.\private$\MyQueue";

DynamicSendPort(Microsoft.XLANGs.BaseTypes.Address)="http://MyOrder.contoso.com";

DynamicSendPort(Microsoft.XLANGs.BaseTypes.Address)="ftp://MyServer/MyDirectory/%MessageID%.xml";

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

QuestionHow to create Dynamic send port for MS CRM 3.0/4.0 in BizTalk 2006
kuldip01
1:24 22 Dec '08  
HI ,

I want to create a dynamic send port for MS CRM 3.0/4.0 adapetr. but i didnt get how to create it? Also i didnt get any methods to set username and password required to access CRM.

CRM Url is : http://localhost:5555

Username: Administrator

Password: password

Orgname: MicrosoftCRM

I installed MS CRM Adapter[Both for 3.0/4.0 common and also separate adapter for CRM 4.0].

Thanks in advance.
AnswerRe: How to create Dynamic send port for MS CRM 3.0/4.0 in BizTalk 2006
Naveen Karamchetti
13:27 24 Mar '09  
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...

GeneralHow to call web service by dynamic port in biztalk 2006
RyanElee
17:59 27 Aug '07  
hi Naveen Karamchetti,

Do you know how to call web service by dynamic http port in biztalk 2006?
Just set the address of the dynamic send port if only? But I have a try for this, I got a internal 500 service error.

Another way, I can comsume the web service successfully by dynamic soap port, But i need to set the SOAP.methodname & SOAP.assembly, it is not a universal way for calling web service dynamically.

How do you think about?

Appreciate you help.
Thanks!
QuestionSetting the Address property
GunnerOlesen
9:40 11 Feb '07  
I have implemented the solution, and it works fine, so i find it is a good working example on how to use dynamic routing. There is one thing -
the filenames in the output directory does not change. The messages
are routed to the correct folders, but given a file name
that looks something like
"Message_%MessageId%.xml" (%MessageId% is replaced by {.....})
and NOT the filename "IgnoreMessage_%MessageId%.xml?
Does anybody know the explanation?



AnswerRe: Setting the Address property
GunnerOlesen
10:59 11 Feb '07  
Sorry - the "wrong" messages were left overs in the distributed material.
I had a spelling error in the "routing" expresion. So the Address property works as expected. D'Oh!
GeneralWhat about other transport types?
WillemM
1:10 20 Oct '06  
How can I use other transportation types in the dynamic sendport?
You're using FILE:// can I do the same with SMTP:// ??

WM.
What about weapons of mass-construction?

GeneralRe: What about other transport types?
WillemM
2:07 20 Oct '06  
Found it, after some poking around with a test orchestration I found out that the following url types are possible:

ftp://
http://
https://
file://
mailto:

WM.
What about weapons of mass-construction?

GeneralHard coded target path not usefull
benjamin wegner
21:27 7 Mar '06  
As far as I understand the biztalk idea, things like path or servernames should be configured after the artifacts has been deployed. When you hard code the target paths, you'll have to redeploy the orchestration every time you change this.
Is there any other option doing something like this? Maybe multiple send ports in your orchestration?

Regards,
Benjamin
GeneralRe: Hard coded target path not usefull
TeddyBeer
23:30 7 Mar '06  
You could have business rules returning the URI where you want the data to be sent to.
The business rules then can be changed live with the business rule composer tool.
GeneralRe: Hard coded target path not usefull
_ABHILASH_MS_
1:21 22 Mar '06  
The author wishes to explore the concept you can return the value of the destination in a numerous ways like a Rule or a helper class whihc return data from any data store say SQL Smile

www.abhilash.in www.biztalkcafe.com http://biztalkland.blogspot.com


Last Updated 1 Mar 2006 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010