Execute or Test a BizTalk 2010 map from .NET

Microsoft BizTalk ESB Toolkit includes a set of helper classes used by the other processes, services, and components in the toolkit. Because these helper classes are also public, you can use them in your own code as required. For example in a BizTalk Orchestration you can use the MapHelper class to perform transformations directly.

The TransformMessage method takes as parameters a string that contains the message to transform and a string that contains the fully qualified name of a map deployed in BizTalk. The method returns a string containing the transformed document.

The Transformation Web service from the ESB Toolkit enables external applications to submit a document to an ESB application and have it transformed using a deployed Microsoft BizTalk map.  But is it also possible to  call directly the MapHelper class from you own code? In order to test it I created an small Windows Form application that calls the MapHelper class and after some tweaking it worked!

The sample tool makes it very easy to execute a BizTalk map. It requires a XML file as input, the name of the assembly and the map name.

 

Changes v1.1  (8/20/2013)

The new features from the BizTalk 2013 MapTester are now also available in the version for BizTalk 2010.

What's New For This Release:
- AssemblyPicker  (from Sander Nefs: http://snefs.blogspot.nl/)
- A new wizard to create an envelope message to wrap multiple input messages.
- Custom MapHelper class to perform BizTalk transformations directly from .NET.
- Measure the execution time of the map.
- User experience changes.

 

How to test a map

First enter the Source file and the fully qualified name of the map and click on Test Map

MapTester.SourceMessage

 
You can now also pick the BizTalk map from an assembly.
AssemblyPicker
 
The output is stored in a file and shown on the Result tab.

MapTester.TransformedMessage

 

How the sample works

In the new version is no longer a reference added to the ESB.TransformServices.dll assembly. It now has a custom MapHelper class to execute the map.

System.Xml.XmlDocument sourceDoc = new System.Xml.XmlDocument(); 
sourceDoc.Load(SourceBrowser.Url.ToString()); 
 
//Fully qualified name of the map deployed in BizTalk. 
string mapName = string.Format("{0},{1}", TestSettings.Name, TestSettings.Assembly);                 
 
string result = null; 
string docSpec = null; 
string messageType = null; 
 
//Measure Start 
long startTick = DateTime.Now.Ticks;                  
 
//This method takes as parameters a string that contains the message to transform and a  
//string that contains the fully qualified name of a map deployed in BizTalk.  
//The method returns a stream containing the transformed document. 
using (Stream stream = MapHelper.TransformMessageStream(sourceDoc.InnerXml, mapName, false, ref docSpec, ref messageType)) 
{ 
    using (StreamReader reader = new StreamReader(stream)) 
    { 
        result = reader.ReadToEnd(); 
    } 
} 
 
//Measure End 
long endTick = DateTime.Now.Ticks; 
long tick = endTick - startTick; 
long milliseconds = tick / TimeSpan.TicksPerMillisecond;

 

Download

You can download the sample tool with the source code here:

http://code.msdn.microsoft.com/Execute-a-BizTalk-map-from-26166441

About the author

Tomasso Groenendijk lives in Netherlands and is a senior integration consultant at Motion10. He has over 15 years’ experience in software development and software design. Tomasso is specialized in application integration with a strong interest in the Windows Azure cloud platform. In 2014, 2015 and 2016 Tomasso was awarded with the Microsoft Azure MVP award. He is an active contributor to the integration community through his work on his blog, MSDN samples, TechNet Wiki and also speaking on events.

 
 
 
MVP profile Tomasso Groenendijk
 
 
Sentinet Product Specialist
 
 
BizTalk360 Product Specialist

Month List