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


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



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(); 
//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;



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


About the author

Tomasso Groenendijk lives in Netherlands and is a Solution Architect at Insight. He has over 20 years experience in software development and software design. Tomasso is specialized in application integration with a strong interest in the Windows Azure cloud platform. From 2014, Tomasso has been awarded six times with the Microsoft Azure MVP award. He is an active contributor to the integration community through his work on his blog, GitHub samples, TechNet Wiki and speaking on events. Furthermore he is an official board member of the Dutch Microsoft Integration User Group.

MVP profile Tomasso Groenendijk
Sentinet Product Specialist
BizTalk360 Product Specialist

Month List