Click here to Skip to main content
15,868,101 members
Articles / Productivity Apps and Services / Biztalk

Exposing a REST/JSON GET endpoint using BizTalk Server 2013

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
24 Jan 2016CPOL3 min read 36.7K   1   1
To Expose BizTalk Schema as a Rest/Json Service with GET method.

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:

  1. Create two Schema for the WCF Service Request and Response
  2. Create a Table and Stored procedure to retrieve the details from the table without passing a parameter.
  3. Create a Stored procedure schema from the created Storedprocedure.
  4. Create a Map to Map the SP Response to WCF Response
  5. Create a Custom Receive Pipeline to promote a fields. Get from the below URL:

https://github.com/BizTalkComponents/HttpDisassembler

  1. Create a Custom Send Pipeline with JSON Encode  to send JSON message back to the service.
  2. Create an Orchestration to execute the Stored proc and convert the Storedprocedure response to WCF Rest Service response.

Steps to Create Solution:

  1. Create a Schema and promote the field as property promotion.

 

Image 1

 

Promote the tenantId field as a Property promotion.

Image 2

Image 3

 

  1. 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.

Image 4

 

  1. Create a Map, StoredProcedure Response to RestAPI response.

 

Image 5

 

  1. 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.

 

Image 6

 

  1. 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\

Image 7

 

  1. Create a Send pipeline JSON Encoder to convert the xml to JSON.

 

Image 8

 

  1. Build and Deploy the solution to Admin Console.

 

  1. Create a Service by following the below steps.

 

Select BizTalk WCF Service Publishing wizard .

Image 9

 

Image 10

 

Image 11

 

Image 12

 

Image 13

 

Image 14

 

Image 15

 

Goto IIS HTTPRestServiceDemo Directory Browsing Enable

 

Then Browse the Service

 

Image 16

Image 17

Image 18

 

Image 19

 

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.

 

Image 20

 

 

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.

 

Image 21

 

Now we successfully Published the RestService.

  1. By Default the Exposed service is enabled for the POST method, now we need to change to GET method.
  2. 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>

 

Image 22

Goto Edit (Variable Mapping)

Image 23

propertyNameSpace == https://Carrier.Schema.PropertySchema

 

Now we converted the POST as GET method successfully.

  1. Now we need to Test the Service.

We can test using Soap UI:

 

Image 24

Image 25

Image 26

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.

Image 27

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:

https://social.msdn.microsoft.com/Forums/en-US/3680aec0-c8be-4f25-8e49-5088e6d37ef6/biztalk-jsonrest-service-with-the-get-method?forum=biztalkgeneral

http://blog.ibiz-solutions.se/integration/exposing-a-rest-get-endpoint-using-biztalk-server-2013/

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) VNB Consulting Service
India India
I am working as a Sr.BizTalk Developer. I have 6+ yrs of experience in Development,Testing, Designing of BizTalk Solution.
I have worked on different domain and exposed my knowledge.

Comments and Discussions

 
QuestionThe property values is populating Pin
Member 1197542918-Mar-16 19:25
Member 1197542918-Mar-16 19:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.