BizTalk Server and ReST

BizTalk Server and ReST

Rate This
  • Comments 4

I have just finished uploading an article and a sample on how to have ReST work with BizTalk Server.

  • The article is available here.
  • The sample is available here.

The article is in the form of a Wiki. So, if you think it can be enhanced in some way, you can simply log in using your Live ID and edit the article. I would strongly recommend doing so instead of waiting for me to fix the article based on any comments I receive. You can also put in your comments for both the article as well as the sample at the respective links.

Pasting an excerpt from the article:

********************************************************************************************************************************

In the previous section we saw how ReST is not SOAP and that ReST supports GET, PUT, POST, and DELETE methods. So, if one has to use ReST with BizTalk Server, the adapter to be used should be able to:

  • Exchange non-SOAP messages.
  • Support GET, PUT, POST, and DELETE methods.

If we look at the adapters available with BizTalk Server 2010, only the HTTP adapter satisfies the first criteria but it does not support GET (it does support the POST method). Similarly, the webHttpBinding (that supports consuming and exposing ReSTful services) available with WCF-Custom adapter can send non-SOAP messages but that too has no way of specifying the HTTP verb to be used. All other adapters either do not support HTTP verbs or always exchange SOAP messages. So, there is no way to have an out-of-box BizTalk configuration to consume a ReSTful service. To use BizTalk Server with ReST, we'll have to do some customizations around HTTP adapter or the webHttpBinding of the WCF-Custom adapter. There is no prescribed way of doing customizations around the HTTP adapter. However, to the webHttpBinding, we can add some custom behaviors that when coupled with webHttpBinding enable BizTalk users to invoke and consume ReSTful services. Through these customizations, we can specify the following:

  • The HTTP method to use in the request (GET, PUT, POST, DELETE).
  • How to form the request URL from operation method parameters (URL path and query string template).
  • How to encode the request body and decode the response.

With WCF-Custom port configuration, there's no way of specifying these customizations directly on the webHttpBinding. So, we'll have to put these values in the request message. After specifying the values as part of the request message and adding a custom behavior to the webHttpBinding, when the request message hits the WCF-Custom port with the webHttpBinding, the custom behavior extracts the values from the request message and frames the required HTTP transport.

Now let us talk a little bit about the customization that would be required on the webHttpBinding. webHttpBinding is WCF-based. WCF enables you to alter messages before they are sent or after they are received through Message Inspectors. A message inspector is an extension to the client runtime and is configured as a behavior. A behavior, in turn, is added to a behavior extension element. This behavior extension element is registered in the machine.config with an element name, which makes it available to be configured as a custom behavior on a WCF-Custom port. For more information, see Extending WCF with Custom Behaviors.

So, to sum it up, to consume a ReSTful service with BizTalk Server, this is what we need to do:

  1. Create a request message that has all the required attributes such as HTTP verb, any parameters required to frame the URL, etc.
  2. Create a message inspector to alter the request message using the attributes specified in the request message.
  3. Create an endpoint behavior to apply the message inspector to the client endpoint.
  4. Create a behavior extension element to enable configuration of the endpoint behavior.

*********************************************************************************************************************************

Leave a Comment
  • Please add 7 and 1 and type the answer here:
  • Post
  • Finally a sample how to deal with REST using BizTalk.

  • Would this make it possible to expose a receive location as a rest service/operation?

  • Great work, but please need ReSTfulness as a core product capability.

  • I can't believe that there isn't an official out of the box adapter for consuming and exposing RESTful services from BizTalk 2010.

Page 1 of 1 (4 items)