Geeks With Blogs
Paul's Petrov Whiteboard [BizTalk, Enterprise Application Integration, Business Process Automation, SOA, .NET]

This time we'll combine loosely-typed BizTalk messaging concept with dynamic mapping to create generic transformation orchestration. Then we'll add it to the message broker created in the first article to make it even more powerful.

Quite often message dispatching task must be combined with some content adaptation: data mapping, filtering, calculation, etc. Generally, maps are used in BizTalk to achieve that. Since maps are based on source and destination schemas we need to find a way to abstract transformation process from specific schema type to common XmlDocument. What makes it possible is XLANGs transform command. This command accepts output message as argument and uses System.Type of BizTalk map. It allows us dynamically load and apply any map type to any message type.

First, we have to author schemas and maps. I created two input schemas for this project: NewEmployee.xsd, NewOrder.xml; two output schemas: Employee.xsd, Order.xsd; and two corresponding maps: NewEmployee_to_Employee, NewOrder_to_Order.I did some changes in DispatchMessage orchestration to integrate with TransformMessage.odx. I added new message variable msgTransformed which is an output from transformation orchestration. Then I simply added Decide shape to check if transformation required for incoming fie. If yes, we pass map key and input message to the TransformMessage.odx using CallOrchestration shape. If no mapping provided then we simply copy incoming message content to msgTransformed:

Again, to retrieve required map name at runtime, we're going to use the same key-value pairs in the configuration file. In our example we used file name as the key so let's follow this trend. If we're gonna store these keys in the same configuration file we need to modify them to keep unique, for example by adding ".MAP" prefix, i.e. <add key="NewEmployee.xml.MAP" value="GenericBiztalkPatterns.Maps.NewEmployee_to_Employee" />.

To keep things clean and reusable I factored out mapping functionality in separate TransformMessage.odx. orchestration. This orchestration contains three parameters: msgInput, mapKey, out msgOutput which are self explanatory. Notice, all message parameters are of XmlDocument type again. The orchestration id very simple itself. Read fully qualified map name by passed in key and get Type of this map:

mapTypeQName = System.Configuration.ConfigurationManager.AppSettings[mapKey];
mapType = System.Type.GetType(mapTypeQName);

Then in ConstructMessage shape just apply transformation:

transform(msgOutput) = mapType(msgInput);

That's how it looks in designer:

I did some changes in DispatchMessage.odx to integrate with TransformMessage.odx. There is new message variable msgTransformed which is going to be an output from transformation. Also, I added Decide shape to check if mapping required. If yes, then input message and map key is passed into TransformMessage.odx through CallOrchestration shape. Ohterwise, input message simply copied to msgTransformed:


Now, all we need is to make sure there're proper entries in the configuration file:

  <add key="NewEmployee.xml" value="file://C:\Projects\Design Patterns\GenericBizTalkPatterns\GenericBizTalkPatterns.MessageBroker\Ports\File.out\employee.xml" />
  <add key="NewEmployee.xml.MAP" value="GenericBizTalkPatterns.MessageBroker.Maps.NewEmployee_to_Employee, GenericBizTalkPatterns.MessageBroker, Version=, Culture=neutral, PublicKeyToken=44e796208f4e4812" />
  <add key="NewOrder.xml" value="ftp://[Your FTP server path here]/order.xml" />
  <add key="NewOrder.xml.MAP" value="GenericBizTalkPatterns.MessageBroker.Maps.NewOrder_to_Order, GenericBizTalkPatterns.MessageBroker, Version=, Culture=neutral, PublicKeyToken=44e796208f4e4812" />
  <add key="FTPUserName" value="[Your FTP username]" />
  <add key="FTPPassword" value="[You FTP password]" />
  <add key="FTPMode" value="true" />
  <add key="FTPRepresentationType" value="Binary" />
  <add key="FTPCommandLog" value="C:\Projects\Design Patterns\GenericBizTalkPatterns\GenericBizTalkPatterns.MessageBroker\ftp.log" />
  <add key="FTPBeforePut_NewOrder.xml" value="" />
  <add key="NotRoutedDestination" value="file://C:\Projects\Design Patterns\GenericBizTalkPatterns\GenericBizTalkPatterns.MessageBroker\Ports\backup" />
  <add key="NotSuportedProtocolDestination" value="file://C:\Projects\Design Patterns\GenericBizTalkPatterns\GenericBizTalkPatterns.MessageBroker\Ports\backup" />

At some point, configuration file can get quite large, that's why I prefer to keep group of settings in individual configuration files, like destinations.config, maps.config, etc., but that's a topic for another article. So far, we've seen how generic messaging concept can help creating flexible agile BizTalk applications. [Source code is available]

Posted on Thursday, January 24, 2008 1:25 PM BizTalk , EAI | Back to top

Comments on this post: Generic BizTalk Patterns: Message Broker with Dynamic Transformation

# re: Generic BizTalk Patterns: Message Broker with Dynamic Transformation
Requesting Gravatar...
Hi. Nice pattern you described. I'm trying to use it with dynamic send ports and SQL Adapter. The Problem is the configuration of send ports in an expression shape. Do you have a suggestion how to solve it? I found many examples for ftp, file and msmq, but not one for Sql Server. Isn't it possible?

Left by Stefan on Feb 15, 2008 7:40 AM

# re: Generic BizTalk Patterns: Message Broker with Dynamic Transformation
Requesting Gravatar...
How do you deploy the app.config in order for the application to use it?


Left by Howard Edidin on Jun 09, 2008 11:49 AM

# re: Generic BizTalk Patterns: Message Broker with Dynamic Transformation
Requesting Gravatar...

I use solution based on MS configuration application block. I will post it as a separate article, but in essence I implement custom file configuration source (IConfigurationSource). The actual file location is read from the registry entry.

Left by Paul Petrov on Jun 09, 2008 3:53 PM

# re: Generic BizTalk Patterns: Message Broker with Dynamic Transformation
Requesting Gravatar...

I posted one example of doing that:

Left by Paul Petrov on Jun 11, 2008 3:26 PM

# re: Generic BizTalk Patterns: Message Broker with Dynamic Transformation
Requesting Gravatar...
Hi, very intersting and usefull article. However, I have a small question, where do you deploy your config file?
Do you add tags in BTSscv.config or somewhere else,
Thanks in advance
Left by Salam on Jan 12, 2010 12:44 PM

# re: Generic BizTalk Patterns: Message Broker with Dynamic Transformation
Requesting Gravatar...
You can keep it in BTNTSvc.config file. In my case, I used custom serializable map in separate XML document. Some examples here
Left by Paul on Jan 12, 2010 8:55 PM

Your comment:
 (will show your gravatar)

Copyright © Paul Petrov | Powered by: