You can modify and/or extend the ​Microsoft BizTalk ESB Toolkit itinerary service's and components to suit your specific requirements. You can create an Orchestrations and publish it as an Itinary Service but you can also create a class (or Pipeline Component) that implements the IMessagingService interface. 
The custom itinerary service that you create acts as an interceptor and is called by the Dispatcher pipeline component.

Custom messaging-based itinerary services, or messaging services, all implement the IMessagingService interface. This interface exposes the Name and SupportsDisassemble properties and the Execute and ShouldAdvanceStep methods.

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 examine also the other methods and properties.

Figure 1. .NET Reflector tool 


To implement a custom itinerary service for messaging:

  1. Create an assembly with a class that derives from IMessagingService; in the Execute method, include all logic necessary to perform modifications to the message or the message context (if any).
  2. Add an entry in the itineraryServices section of the Esb.config file for your service (in “C:\Program Files\Microsoft BizTalk ESB Toolkit ..

    Figure 2.
  3. Now you can create an itinerary with the custom Itinerary Service. (for example a Tracing Service)

    Figure 3.
  4. Add the assembly to the Global Assembly Cache.


Once the itinerary is deployed to the Itinerary Store database and the custom Itinary Service is placed in the GAC, the solution is ready to be tested.
Create a Receive Port and a Receive Location with the BizTalk Administration Console and drop a message in it.

Run the DebugView tool to watch the trace output.

Figure 4. DebugView tool 

Code Samples

Through the MSDN Code Gallery and download center you can find a number of code samples:

See Also

Read suggested related topics:

Another important place to find an extensive of BizTalk related articles is the TechNet Wiki itself. The best entry point is BizTalk Server Resources on the TechNet Wiki.