BizTalk Server 2013: Exposing a REST/JSON GET endpoint
Introduction
As we know how to expose a WCF service as RESTFul service using the POST method. That is direct as we are doing for the exposing normal WCF service.
I tried with the POST method for the RestFull service and I have created it in an hour. But doing the GET endpoint is painful. As we don’t have much document Online. So I have done so much research and found a very good post provide by** Steef Jan Wiggers (Microsoft Azure MVP).**
Background
Scenario:
Client need to trigger the service without any input, our RestAPI service should send back the response with JSON format by executing the SQL StoredProcedure.
Using the code
Solution:
- Create two Schema for the WCF Service Request and Response
- Create a Table and Stored procedure to retrieve the details from the table without passing a parameter.
- Create a Stored procedure schema from the created Storedprocedure.
- Create a Map to Map the SP Response to WCF Response
- Create a Custom Receive Pipeline to promote a fields. Get from the below URL:
https://github.com/BizTalkComponents/HttpDisassembler
- Create a Custom Send Pipeline with JSON Encode to send JSON message back to the service.
- Create an Orchestration to execute the Stored proc and convert the Storedprocedure response to WCF Rest Service response.
Steps to Create Solution:
- Create a Schema and promote the field as property promotion.
http://www.codeproject.com/KB/biztalk/1073931/Image01.jpg
Promote the tenantId field as a Property promotion.
http://www.codeproject.com/KB/biztalk/1073931/Image02.jpg
http://www.codeproject.com/KB/biztalk/1073931/Image1.jpg
- Add SQL StoredProcedure Schema à Add Generated Item à Consume Adapter service à Add
Provide the corresponding SQL connection string and select Strongly Typed Stored procedure, It create a Schema.
http://www.codeproject.com/KB/biztalk/1073931/Image2.jpg
- Create a Map, StoredProcedure Response to RestAPI response.
http://www.codeproject.com/KB/biztalk/1073931/Image3.jpg
- Create Orchestration to retrieve stored procedure and map the SP response to the WCF Service response and send back to the same req-resp port.
http://www.codeproject.com/KB/biztalk/1073931/Image4.jpg
- Create a Receive Pipeline to promote the fields which we promoted.
Get the HTTP disassembler Pipeline component from the below URL:
https://github.com/BizTalkComponents/HttpDisassembler
Folder: src\HttpDisassembler\
http://www.codeproject.com/KB/biztalk/1073931/Image5.jpg
- Create a Send pipeline JSON Encoder to convert the xml to JSON.
http://www.codeproject.com/KB/biztalk/1073931/Image6.jpg
- Build and Deploy the solution to Admin Console.
- Create a Service by following the below steps.
Select BizTalk WCF Service Publishing wizard .
http://www.codeproject.com/KB/biztalk/1073931/Image7.jpg
http://www.codeproject.com/KB/biztalk/1073931/Image8.jpg
http://www.codeproject.com/KB/biztalk/1073931/Image9.jpg
http://www.codeproject.com/KB/biztalk/1073931/Image10.jpg
http://www.codeproject.com/KB/biztalk/1073931/Image11.jpg
http://www.codeproject.com/KB/biztalk/1073931/Image12.jpg
http://www.codeproject.com/KB/biztalk/1073931/Image13.jpg
Goto IIS HTTPRestServiceDemo Directory Browsing Enable
Then Browse the Service
http://www.codeproject.com/KB/biztalk/1073931/Image14.jpg
http://www.codeproject.com/KB/biztalk/1073931/Image15.jpg
http://www.codeproject.com/KB/biztalk/1073931/Image16.jpg
http://www.codeproject.com/KB/biztalk/1073931/Image17.jpg
DocumentSpecname : <Name>, <Assembly>
Eg: DemoSchema.JsonCarrier, DemoSchema, Version=1.0.0.0, Culture=neutral, PublicKeyToken=36c63864bb129606
Provide the above details in the DocumentSpecName and Enable the Receive Location by selecting appropriate Pipeline.
http://www.codeproject.com/KB/biztalk/1073931/Image18.jpg
To Enable the MetaData follow below steps:
Goto C:\inetpub\wwwroot\HTTPRestServiceDemo Web.config
<behavior name="ServiceBehaviorConfiguration">
<serviceDebug httpHelpPageEnabled="true" httpsHelpPageEnabled="false" includeExceptionDetailInFaults="false" />
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="false" />
</behavior>
Make httpGetEnabled= True as above sample.
http://www.codeproject.com/KB/biztalk/1073931/Image19.jpg
Now we successfully Published the RestService.
- By Default the Exposed service is enabled for the POST method, now we need to change to GET method.
- Follow the below steps to make the GET Endpoint.
GOTO Receive Location Configuration
Under HTTP Method Copy paste the below code:
<BtsHttpUrlMapping>
<Operation Method="GET" Url="/tenantId/{pid}" />
<Operation Method="GET" Url="/tenantId" />
</BtsHttpUrlMapping>
http://www.codeproject.com/KB/biztalk/1073931/Image20.jpg
Goto Edit (Variable Mapping)
http://www.codeproject.com/KB/biztalk/1073931/Image21.jpg
propertyNameSpace == https://Carrier.Schema.PropertySchema
Now we converted the POST as GET method successfully.
- Now we need to Test the Service.
We can test using Soap UI:
http://www.codeproject.com/KB/biztalk/1073931/Image22.jpg
http://www.codeproject.com/KB/biztalk/1073931/Image23.jpg
http://www.codeproject.com/KB/biztalk/1073931/Image24.jpg
Change the Resource URL from /HTTPRestServiceDemo/Service1.svc to /HTTPRestServiceDemo/Service1.svc/tenantId/34 As we promoted the tenantId so the message will automatically triggered to BizTalk.
http://www.codeproject.com/KB/biztalk/1073931/image25.jpg
You will get the response as the above screenshot.
Points of Interest
- 1. How to Expose the WCF service as a Rest/Json Service.
- 2. How to Use GET endpoint using BizTalk Server
- 3. Learn to expose BizTalk Schema as WCF Rest service thro JSON.
Reference:
http://blog.ibiz-solutions.se/integration/exposing-a-rest-get-endpoint-using-biztalk-server-2013/