The support for REST has been anticipated for a long time by BizTalk developers. A majority of the services in the cloud these days is REST based. When exposing a public API over the internet to handle CRUD operations on data REST has now generally been considered the best option. Twitter, Google, Salesforce, eBay, Amazon all offer REST API's to use their services. Not only these, but many more companies support REST or will support it as the number of mobile devices and light weight rich (Ajax) web applications will increase significantly coming years.
In previous posts on the new adapters available with BizTalk Server 2013 I discussed both the Relay adapters: BasicHttp, NetTcpRelay and the Service Bus SB-Messaging. In this post I like to discuss the WCF-WebHttp adapter in his current state in the BizTalk Server 2013 Beta. The adapter offers the capability to send messages and to receive messages from a RESTful Service endpoints.
Note: Since BizTalk sends out message bodies you will need to configure the adapter to prevent this for the GET and DELETE request . This configuration currently is not available yet and the current option (with BizTalk Server 2013 Beta) is to remove the message body with a pipeline.
Below you find a diagram of a scenario I like to walk-through, where I consume a RESTFul Service endpoint of the US Federal Aviation Administration. From a client application I will send a request for the status of an airport, which will by BizTalk to the Restful service endpoint.This endpoint will provide the status of a given airport based upon the airport code I provide within the request URL. The result will be routed back to the client application.
The GET request is the fundamental, widely used operation in REST world. You can simply visit a URL in a browser (or programmatically); for instance in this case for instance the following URL http://services.faa.gov/airport/status/SEA?format=xml and the browser returns a machine understandable structured data like below:
To get this done through BizTalk you need to configure a send port with the WCF-WebHttp adapter. The following picture shows the WCF-WebHttp REST adapter configuration. In the general tab the address URL, the HTTP Method and URL mapping are specified.
In the address the URI for the REST interface where the message is sent is specified. The HTTP method to URL mapping can be specified as a singular format or a multi-mapping format. In this sample it is multi-mapping format. The Variable mapping is specified by click the Edit… button.
Variable mapping is a technique that enables you to parameterize your request to a RESTful endpoint. Hard coding the airport code is not a viable option. The other tabs provide you ability to configure the time-out and encoding-related properties, define the security capabilities of the WCF-WebHttp send port, configure the endpoint behavior for the send port and configure the proxy setting for the WCF-WebHttp send port. For this sample all these are left untouched (default).
When I start the client I can select an airport in the US and request the status.
The request will be sent to an WsHttp endpoint in BizTalk Server. This endpoint is created through BizTalk WCF Publsihing Wizard exposing the following schema.
The request will be routed to the send port with WCF-WebHttp adapter, which will sent the request i.e. request resources through the GET method based on the following:
The result is mapped back to response message of the WsHttp endpoint and returned to client for rendering the UI. You can download this solution from the Code Gallery.
Other resources related to the WCF-WebHttp worth to check out are:
In the next post I will discuss the SFTP adapter.
Labels: BizTalk, BizTalk Server 2013, New Adapter Series