essage transformations have long been an integral part of EAI projects. Disparate systems participating in an integration project need transformations as dictated by their respective standards. As an EAI tool, BizTalk provides excellent support for message transformations.
BizTalk carries out transformations primarily with the BizTalk Mapper, which has evolved significantly from its first version in BizTalk Server 2000. A map in BizTalk can be created graphically by defining a set of relationships between two or more XML messages. Much like its predecessor, BizTalk 2004 Mapper allows users to define relationships by simply drawing a line between the two schemas. More complex transformations can be established using functoids, which also should be familiar to users who've used the Mapper.
This article demonstrates the ability of BizTalk Server to carry out message transformations with amazing ease. It walks through the processes of simple message transformations with the Mapper and extends them to some complex scenarios that are common in EAI projects. The intricacies of functoids also are explored, along with a demonstration of how to create a brand new functoid. Finally, the article looks at some lesser-known aspects, such as transformations with multiple-source and destination messages.
Creating the Map File
The message schema is a prerequisite for any BizTalk project. An XML schema must be defined for each message used in a BizTalk project. Creating a BizTalk map involves specifying the source and destination schemas that need to be mapped together.
|Figure 1. Construct Message Scope: The transform shape must be within a Construct Message Shape. This takes care of the fact that messages are immutable by nature.|
In a BizTalk project, a map can be created in two ways:
1. Within the orchestration Once you have added the schemas and created the messages, simply drop a transform shape on the orchestration flow. This will automatically add a Construct Message shape that will contain the transform shape (see Figure 1). Visual Studio adds the construct message shapes as messages, which are supposed to be immutable. Hence, to transform a message, you need to actually create a new one. The old message stays the same so the transformations can be tracked throughout the scope of the message.
To begin the process of mapping the values, just double click on the transform shape. On the popup dialog, select the "Create a new map" option and specify the messages that you want as input and output (see Figure 2). The input and output schemas for the map will be decided accordingly. Make sure the "When I click OK, launch the BizTalk Mapper" option is checked before you click OK. This will create a new map and open it up for you. You can work with this simple map by dragging fields from the source schema to the target schema.
|Figure 2. Transform Configuration: BizTalk provides functionality to create a map with schemas derived from the messages being used. This functionality also helps in creating maps with multiple input or output messages.|
2. Independently by adding a map file to the project To create a map independent of the orchestration, use the regular files add method as you would in any Visual Studio project. Once you've added the schemas to the project, simply right-click on the project and select Add New Items. In the popup dialog, select the BizTalk Map file (see Figure 3). This will create a new BizTalk Map file where you will need to specify the source and the target schemas.
Working with the Map File
The BizTalk Mapper provides an easy and efficient interface to interact with the maps. Primarily, the Mapper provides sections for the Source Schema, the Mapping Area, and the Destination Schema (see Figure 4
|Figure 3. Add a Blank Map: Add a blank map to the project using the "Add New Item" context menu on the project.|
The Source Schema section allows you to configure the map's source schema, which you use as the input to the map. The Destination Schema section allows you to configure the map's destination schema, which the Mapper will use to generate the output.
The mapping Area is divided into a number of pages. Each page can contain its own functoids and links, which you normally wouldn't use unless you had a really complex map that required multiple pages. The pages can also act as partitions in case you have multiple input or output schemas.
|Figure 4. The Mapper: The BizTalk Mapper contains sections for Source schema(s) to map from, Destination schema(s) to map to, and the mapping area that does the actual processing. The Functoid toolbox provides access to the built-in, as well as the custom, functoids.|
The functoid Toolbox is an integral part of BizTalk mapping. It is a library of functoids that can be used to perform various operations on the schemas. A functoid is basically a .NET assembly that takes inputs from the source (schema element or another functoid), processes them, and delivers the output either to the target schema or simply to another functoid. The functoids normally fall into the following categories:
In addition to these, users can add custom functoids in the Toolbox. Custom functoids normally are used when dealing with more complex conversions that cannot be accomplished easily with the normal set of functoids. An example could be something like encryption/decryption or Fahrenheit-to-Celsius conversions.