Publish REST Service from BizTalk Server 2013 WCF-WebHttp Adapter
BizTalk Server 2013 provides REST Services support and it makes it easy to consume and publish REST services. I saw many example of consuming REST Services in BizTalk, however could not find anything for publishing REST Services on BizTalk. In this article I am going to detail on steps of publishing REST services.
For this article I referred to Steve-Jan Wiggers sample which can be found at following location http://code.msdn.microsoft.com/BizTalk-Server-2013-WCF-e3e4a4f9
This sample talks about consuming a REST service to get airport status. In order to test the sample Steve has a Windows Form based application which invokes a WCF service exposed by BizTalk.
I further extended the sample to expose REST service using WCF-WebHttp Adapter and tested the whole scenario with Fiddler and IE. The details steps are as follows:
By this time, I assume you have run the above mentioned code sample
- Run WCF Publishing Wizard from Visual Studio Tools Menu:
- From the WCF Publishing Wizard, Select WCF-WebHttp Adapter on Service endpoint option and click Next
- Choose default option on AppFabric Connect, as we are not concentrating on ServiceBus right now and click Next
- Choose Create a Request-Response Receive Port and click Next
- Choose IIS publish location and select allow Anonymous access and click next
- The wizard will now display the summary page of the selection
- Click Create to publish the REST Service:
Few points to note after service is published:
- The WCF service wizard does not ask for any BizTalk Orchestration and Schema details Or Service Operation details as it does in other WCF service publishing. At first I thought there is something wrong, however then I realized that for REST services you do not need metadata information so there is no need to define the service operation.
- Service is published in IIS using default app pool of the IIS web site selected on the Wizard, if the app pool of the site does not have required BizTalk access, please change app pool.
- The name of the service is created as Service1.svc, for this sample to work you do not need to change the name.
- Make sure your service app pool does not have any other service running under it, e.g. if in the original sample, you published as WCF service and that service is running under the same account as REST service is running, you will start getting the following error:
You can now check the service by running the Service1.svc URL in IE and see if you are getting the service page successfully.
Now check out the BizTalk Receive Location which was created by WCF Service Publishing Wizard. You now need to configure the BizTalk operation you want your REST Service to support. The default operation configuration is not correct and should be changed as shown in below steps:
- Open the Receive Location Transport Type (Adapter) Configuration:
- Check out the HTTP Method and URL mapping box, its not what we want here, so we changed it to a GET operation with a URL /status/{airportcode}, where airportcode is a variable which will be mapped with a message context as shown below:
- The mapping of variable {airportcode} with message context properties allows BizTalk adapter to write the context property to incoming request and also allows mapped message context property to be used as a replacement while sending the request to a REST service.
- This configuration now allows One REST operation 'GET' with URL http://localhost/.../Service1.svc/status/BNA where BNA is the airportcode
If you now browse this URL in IE, then you should see a response similar to the response of http://services.faa.gov/airport/status/SEA?format=xml. Because in BizTalk we are just forwarding the request to faa.gov REST service.
You can also use Fiddler to create an REST request as shown below
Fiddler Request
In case of GET operation, there is no message body required, which can be ignored completely. However in some operation like POST, you need the message body. In such cases body can be supplied with appropriate content-type in the HTTP header.
I hope it helps you.