Creating a Custom Itinerary Messaging Service for ETW Tracing

ETW Tracing from the BizTalk Customer Advisory Team (CAT) is now increasingly used by developers for tracing in BizTalk applications. In the ESB toolkit it’s not implement so I wanted to see if it’s difficult to create a custom Messaging Service that uses ETW Tracing.


On MSDN on the Creating a Custom Itinerary Messaging Service page is explained how to create a custom Messaging Service. The following methods and properties are required:

  • The Name property is the name of the service as it will appear in an itinerary. It must match the configured name in the itinerary services configuration in the Esb.config file.
  • The SupportsDisassemble property indicates whether the custom messaging service you are creating supports disassemble and the execution of multiple resolvers.
  • The ShouldAdvanceStep method takes in the current itinerary step, and the current message, and returns a Boolean value that indicates whether the dispatcher should advance the itinerary after the service executes. In almost all cases, this method should return true.
  • The Execute method is of greatest importance for a messaging service and contains the logic that will be executed at run time. It takes in the pipeline context, the message, the resolver string, and the current itinerary step; and it returns the updated message.
In the code example on MSDN is only the ExecuteRoute method shown that is called by the Execute method. This method is not needed when you create your own Messaging Service. Therefore I used Reflector to disassemble the Routingservice to get also the other methods and properties.
On the Best Practices for Instrumenting High Performance BizTalk Solutions blog post from the CAT team you can get the source code for the ETW tracing.
In the example below is the “ExecuteTracing” method shown that is specific for the Tracing Service:
public IBaseMessage ExecuteTracing(IPipelineContext context, IBaseMessage msg, 
string resolverString) { // A call to the TraceIn method at the very beginning of an instrumented code. Guid g = TraceManager.PipelineComponent.TraceIn(); IBaseMessage message; if (context == null) { throw new ArgumentNullException("context"); } if (msg == null) { throw new ArgumentNullException("msg"); } try { // Get context properties from message string interchangeID = msg.Context.Read(BtsProperties.InterchangeID.Name,
BtsProperties.InterchangeID.Namespace) as string; string messageType = msg.Context.Read(BtsProperties.MessageType.Name,
BtsProperties.MessageType.Namespace) as string; string receivePortName = msg.Context.Read(BtsProperties.ReceivePortName.Name,
BtsProperties.ReceivePortName.Namespace) as string; string inboundTransportLocation = msg.Context.Read(BtsProperties.InboundTransportLocation
.Name, BtsProperties.InboundTransportLocation.Namespace) as string; // Writes an information message to the trace. TraceManager.PipelineComponent.TraceInfo("[InterchangeID: {0}]", interchangeID); TraceManager.PipelineComponent.TraceInfo("[MessageType: {0}]", messageType); TraceManager.PipelineComponent.TraceInfo("[ReceivePortName: {0}]", receivePortName); TraceManager.PipelineComponent.TraceInfo("[InboundTransportLocation: {0}]", inboundTransportLocation); message = msg; } catch (Exception exception) { EventLogger.Write(MethodBase.GetCurrentMethod(), exception); // Writes the exception details to the trace. TraceManager.PipelineComponent.TraceError(exception, true, g); throw; } // Writes an informational event into the trace log that a method is about to complete. TraceManager.PipelineComponent.TraceOut(g, "[Completed trace]"); return message; }
In the esb.config in “C:\Program Files\Microsoft BizTalk ESB Toolkit 2.1” you have to add your
custom Itinerary Service.
Now you can create an Itineray with the custom TracingService:
The created itinerary can be tested with the Itinerary Test Client that is located in the ESB Toolkit
sample applications
Trace output:


In principle, it’s not very difficult to create a custom Messaging Service. Still it took a lot of time to create the service and to got the itinerary running because it’s not so well-documented,.

You can download the sample Messaging Service 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