BizTalk Server 2013: New Adapters Series: WCF-WebHttp
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:
http://services.faa.gov/airport/status/SEA?format=xml
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:
Cheers,
Steef-Jan
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:
http://services.faa.gov/airport/status/SEA?format=xml
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:
- Exploring REST Capabilities of BizTalk Server 2013 (Part 1: Exposing REST Endpoints)
- Exploring REST Capabilities of BizTalk Server 2013 (Part 2: Consuming REST Endpoints)
- REST (WCF-WebHttp) adapter in BizTalk Server 2010 R2 and code
- BizTalk and Rest Example from BizTalk Saturday
Cheers,
Steef-Jan
Comments
The source code can be found at the MSDN code gallery. The URL is http://code.msdn.microsoft.com/BizTalk-Server-2013-WCF-e3e4a4f9
REST URL:
Actual URL:
https://ServerName/1.0/channelcatalog/y8xpsfey4xjfa5omtcew5kc6s3j9j7p9ur?modifiedafterdatetime=2010-08-10T00:00:00
my wcf-webhttp configurations are:
Address URI (https://ServerName/1.0/)
HTTP Method and URL Mapping with
But Request ended with below exception.
Error Message:
The adapter failed to transmit message going to send port "SndRestAx" with URL "https://ServerName/1.0/". It will be retransmitted after the retry interval specified for this Send Port. Details:"System.Net.WebException: There was no endpoint listening at https://ServerName/1.0/ that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
I can access this using C# Code. Can you please advice what is missing in this configuration?