Monday, January 13, 2014

Publish REST Service from BizTalk Server

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:
"Registering multiple adapter types within the same process is not a supported configuration. For e.g. HTTP and SOAP receive adapters cannot co-exist in the same process"

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.
 
 

8 comments:

vdha said...

Hello Vikas,

I have created the same way the REST service and the service window opens successfully. Even after passing parameter I am just getting the same service window

Do I need to change anything in the web config?? I am really new to this.And I am really stuck. Any help with this is greatly appreciated. Thanks

vdha said...

http://localhost/ServiceCGA/Service1.svc?id=J000123134

Even this just shows the service window

vdha said...

Can I get the msi of the application, so it will great

Unknown said...

Hi,
i tried running this sample and i am getting below error.
Routing Failure Report for "Routing Failure Report for "WcfReceivePort_BizTalkWcfServiceRestAirport/Service1" and also if i go and check the message part ,it is empty. I am not sure how this message can pass to biztalk since it does not have a message body.

This sample will not work unless you supply a message body to the message.

soumya said...

thanks for providing the valuable information ..keep update with your blogs..i found this article similar to your blog once check it out Biztalk Online Training Hyderabad

fillikir72518 said...

I found your blog web site on google and verify a couple of of your early posts. Proceed to keep up the excellent operate. I simply extra up your RSS feed to my MSN Information Reader. Seeking forward to studying extra from you later on!… online casino

Bhavani Singh said...

I think the same

Bhavani Singh said...

HI,
Without body how Orchestration will get triggered and how can we use promoted property(AIRPORTCODE) where it is promoted?