A few posts ago I had a bit of a whinge about the limitation of a map for a response message in a request response port. The basic problem was I was returning a common schema based message to the port which needed to be mapped to a different format depending on which receive location associated with the port had initiated the process. The send side was fine in that you can send two different input messages which the port can then have two maps, 1 for each message type to map to the common schema.
The problem was on the response the input was the same in both cases so you couldn’t resolve which map to execute. See the below post for more details on this:
This made me to begin thinking about if we could execute the map from the pipeline rather than the port. The difference is that the pipeline is specific to the receive location and you wouldn’t have the problem of resolving the map then.
From another recent post about testing Maps I discussed how you could execute a map from C# code to help you test it. I then begun to put two and two together to see if it would make four. Or if BizTalk would have other ideas J
In the sample I will have a basic input message and a basic output message. The bog standard FirstName/Surname à FullName example. The messages will be mapped with the map in the picture below:
I will then create a pipeline which will use the XmlDisassembler and the ExecuteMap pipeline component like in the below picture.
The pipeline component can be used in a receive or send pipeline and can be used in any stage except disassemble/assemble. The pipeline component has the properties which are displayed in the below picture:
The key properties are:
Assembly Name – This is the strong name of the assembly containing the map
Map Type Name – This is the full name of the type which represents the map. From the Visual Studio IED you can get this from the properties of your map
Output Message Schema Strong Name – This is required to set the correct context property value for the output message. This should be in the format of <Message Full Type Name, Assemble Strong Name> (eg: Acme.BizTalk.Samples.Schemas.OutputSchema, Acme.BizTalk.Samples.Schemas, Version=0.0.0.0, Culture=neutral, PublicKeyToken=PBRTYEFG124)
The Pipeline Component
The pipeline component needs to perform 3 key tasks:
1. Copy the input message
2. Execute the map
3. Create the new message and context to return to the pipeline
The first thought you may have is “why do you need to copy the input message”?. Good question, the first time I did this I didn’t need to, but when I used the component in a pipeline which also contained a disassemble component I started to get a problem because when the map is executed the TransformBase object will dispose the input message stream which caused the Disassembler component to log an error.
Im not really going to go through every line of code in this article, if you want to take a look at the pipeline component then download the sample. In the pipeline component I have made it easy to see what is going on by having 3 private methods which do the 3 actions I have listed above.
Testing the Component
When it came to testing the pipeline component I have used the technique I mentioned in a previous article about how to test pipelines. The following code snippet shows how this test was written.
As you can see the test is pretty simple and does the following actions:
1. Creates the input message
2. Creates the pipeline in code which contains an instance of the
3. Executes the pipeline
4. Checks the output message is as expected in the mapped format
One final thing on the testing is you may also want to check the overridebuild.targets files which show that I am adding to the GAC the assemblies containing the pipeline component and also the BizTalk artifacts. This needs to be done in order for them to be used and tested.
Word of warning
In this sample I have only provided enough to show the pipeline component working (testing it with the Pipeline Component Test Library), I have used this in a sample BizTalk application which I may look to demonstrate at somepoint in the future so yes it can work. I have also focused on finding out if the concept will work so you will want to review the code and optimise some bits before you would use it. The main word of warning though is that I haven’t done anything with this in terms of performance or serious testing so if you plan to look at this technique then don’t forget to do that.
In summary for this article the answer is yes you can create a pipeline component which will execute a map and it can fit into BizTalk. I think there will be occasions when someone will want to do this and maybe this article can help.