POST method at Receive Port

POST Method does not send data in URL Parameters as GET Method sends. In Post method, Rest Service sends data in Message body. Mostly this is in json format. When BizTalk Receive this file, then through the use of JSON decoder pipeline component, BizTalk convert the json into xml format.

For Pipeline configuration related information, you can refer to below reference:

https://vkbiztalk.wordpress.com/2017/06/14/biztalk-with-rest-services/

At BizTalk Receive port we just adding a   below details in HTTP Method and URL mapping in Wcf-WebHttp adopter configuration.

<BtsHttpUrlMapping><Operation Name=”<Name>” Method=”POST” Url=’/OperationName/Request’ /></BtsHttpUrlMapping>

Rest11.jpg

Here no need to do anything with Variable mapping. Apply “Content-Type:application/json” to process data as JSON.

rest15.jpg

Note: For Get Operation we have to keep GET verb in Incoming Message, for Post operations keep blank only.

POST Method at Send Port:

In case of when BizTalk consuming Rest Service through its Send Port with Wcf-WebHttp adopter, then its configuration is same as in Receive Port except one nominal change in below configuration.

<BtsHttpUrlMapping><Operation Name=”” Method=”<REST METHOD>” Url=’/OperationName/Request’ /></BtsHttpUrlMapping> 

There is not require to provide Operation name, we can leave it blank as above.

Advertisements

GET method at Receive Port

When we publish BizTalk as REST Service, then it’s not directly linked with Schema or Orchestration like WCF or Web Service does. in my previous blog, I have mentioned how to publish BizTalk as REST Service with help of BizTalk WCF Service Publishing Wizard Tool.

https://vkbiztalk.wordpress.com/2017/06/17/publish-biztalk-as-rest-service/

Here when we define the action configuration in Receive Location in that we provide Message Context property BTS.Operation for Operation Name, through this message context property, incoming message can link with orchestration Receive Port or Send Port with applying details in Filter. In below example

<BtsHttpUrlMapping><Operation Name=”TESTGETMETHOD” Method=”GET” Url=’/OperationName/Request?Param1={param1}&amp;Param2={param2}’ /></BtsHttpUrlMapping>

Here Operation name is TESTGETMETHOD. So BTS.Operation Message Context Property is stand for TESTGETMETHOD.

For Pipeline configuration related information, you can refer to below reference:

https://vkbiztalk.wordpress.com/2017/06/14/biztalk-with-rest-services/ 

The purpose of enabling GET operation is to fetch data from target system. Other perspective is when request parameters are few in count wise, then we can go with GET API URL.

We will discuss the configuration details at receive location transport level for GET operation.

  • Promote the elements (Param1 and Param2) from message schema whose elements are going to use in GET API URL.
  • Navigate transportation configuration of the REST API receive location and add below text in HTTP method and URL mapping shown in below snap.
  • <BtsHttpUrlMapping><Operation Name=”<Name>” Method=”GET” Url=’/OperationName/Request?Param1={param1}&amp;Param2={param2}’ /></BtsHttpUrlMapping>
  • If there is not require any parameter in GET method then no need to add parameters in BizTalk Schema.
  • Rest11.jpg
  • Map the elements with property schema element names and namespace as below.

rest14.jpg

In GEt method of REST Service, there is no message body. Information is sending in URL as Parameter as in below example:

http://localhost/BizTalkRestService/Service1.svc/Request?Param1=Test1&Param2=test2

here Param1 and Param2 are the two parameters of the GET method. Now We need to understand how BizTalk work with this. In above screen shot we are defining Variable Mapping. In variable Mapping, we are assigning parameters with Property Schema. We need to define Property Schema variable with Message Context Property. Otherwise it will not assign any value.

Rest13_PropertySchema.jpg

Create your property schema with those properties, set the Property Schema Base to MessageContextPropertyBase.

When BizTalk receive request with JSON decoder pipeline, then its create message.

Receive location transportation url would be like this: /BizTalkRestServiceTest/Service1.svc

GET Method at Send Port:

In case of when BizTalk consuming Rest Service through its Send Port with Wcf-WebHttp adopter, then its configuration is same as in Receive Port except one nominal change in below configuration.

<BtsHttpUrlMapping><Operation Name=”” Method=”<REST METHOD>” Url=’/OperationName/Request’ /></BtsHttpUrlMapping> 

There is not require to provide Operation name, we can leave it blank as above.

Publish BizTalk as REST Service

One of the features in BizTalk 2013 R2 is to integrate REST API with other systems/entities. As data process via JSON format we use JSON relevant pipelines to have syntax transformation (JSON to XML and vice versa).  In this article, we will share how to expose REST service in BizTalk and configure it at receive and send port level.

For more about json pipeline, you can refer to my previous blog BizTalk with Rest Service.

https://vkbiztalk.wordpress.com/2017/06/14/biztalk-with-rest-services/

We can categorize aforementioned process into below steps.

Step1: Expose REST API in BizTalk and apply in Receive stage.

Step2: Apply GET method at Receive Port

Step3: Apply POST method at Receive Port

Step4: How to test from Postman UI

Step1: 

Configure REST API using BizTalk WCF Service Publishing Wizard so that it creates service in IIS and Receive location in admin console.

  • Open BizTalk WCF Service Publishing Wizard Tool and click on Next button in Home page and below screen populates.
  • Select WCF-WebHttp adapter and enable second check box and select respective BizTalk application name and click on Next.

Rest1.jpg

Click Next in below screen

Rest2.jpg

Select Receive Port Type as per Business requirement as below screen

Rest4.jpg

Provide relevant name in URL for the service as below screen

Rest5.jpg

Click Next

Rest6.jpg

Now you can see the XSLD has ready to generate for this Rest Service. Click on Create> and finish the process.

Rest7.jpg

Now the BizTalk WCF Service Publishing Wizard work is done. Next is just configuration change require on IIS and Receive Port.

Open IIS manager and select the BiztalkRestServiceTest Service and set up the Advance Settings

Rest8.jpg

Start the Newly Created Receive Location in BizTalk Admin Console, then browse the Service from IIS. By default, its URL is created with Service1.svc.

Rest9.jpg

Ensure that below settings available in web.config file.

Rest10.jpg

WCF Service in IIS and BizTalk Receive location is created so far.

In below reference, its defined to convert .svc url into REST API url.

Convert .svc URL to Rest API URL

https://vkbiztalk.wordpress.com/2017/06/17/convert-svc-url-to-rest-api-url/

We can change the URL as defined above. It’s not recommended but good to look that BizTalk publish as REST Service then its URL also look like as REST Service.

Step2:  Apply GET method at receive port.

Receive Port Configuration is provided in next blog as below:

https://vkbiztalk.wordpress.com/2017/06/17/get-method-at-receive-port/

Step3: Apply POST Method at Receive Post:

Receive Port Configuration is provided in next blog as below:

https://vkbiztalk.wordpress.com/2017/06/19/post-method-at-receive-port/

 

 

Convert svc URL to REST API URL

When we publish BizTalk as REST Service, then it’s generate as below by default.

http://localhost/<ApplicationName>/Service1.svc

when we apply REST verb with this URL, then it’s become as below for Business User.

For GET Method:

http://localhost/<ApplicationName>/Service1.svc/Request?Data1={data}&Data2={data}

For POST Method:

http://localhost/<ApplicationName>/Service1.svc/Request

We can change the Service1 name with some other name but can’t change the .svc.

So, for outer world (Consumer), it’s look like they are consuming the WCF Service instead of REST Service.

So, making feel like as REST Service we need to do some small thing as below:

  • Install Microsoft Rewrite URL module 2.0 (it’s freeware) for IIS to accept the rewrite tags in service configuration files.

https://www.microsoft.com/en-in/download/details.aspx?id=7435

  • Add below rewrite module entries in service web.config file to enable us to use api name in service URL.

<system.webServer>

<rewrite>

<rules>

<rule name=”TestService1”>

<match url=”/Service1(.*)” />

<action type=”Rewrite” url=”Service1.svc/{R:0}” />

<conditions>

<add input=”{REQUEST_METHOD}” pattern=”GET” />

</conditions>

                     </rule>

                     <rule name=”TestService2”>

<match url=”/Service2(.*)” />

<action type=”Rewrite” url=”Service2.svc/{R:0}” />

<conditions>

<add input=”{REQUEST_METHOD}” pattern=”POST” />

</conditions>

</rule>

</rules>

</rewrite></system.webServer>

  • URL will refer as below instead of Service1.svc at postfix.

GET Method:

http://localhost/<ApplicationName>/api/Request?Data1={data}&Data2={data}

For POST Method:

http://localhost/<ApplicationName>/api/Request

BizTalk with REST Service

Now in BizTalk 2013 R2 release, Microsoft provide the communication with Rest Services through WCF-WebHttp adapter. Here are below things added in BizTalk to consume and publish REST Service through BizTalk.

  1. WCF-WebHttp adapter- to communicate with REST Service
  2. JSON decoder pipeline component- to convert Json file into xml format in Receive Pipeline.
  3. JSON encoder pipeline component- to convert xml file to Json in Send Pipeline.
  4. JSON Schema Wizard- To generate xsd from json file.

as we know RESTService has always prefer to have data in json format.

Note: Sometime when RESTService respond with empty message then BizTalk will generate the Object Reference is not found error in JSON decoder pipeline. Micorsoft has release the hotfix for that. You can download from below site.

URL:

https://support.microsoft.com/en-us/help/4020011/fix-wcf-webhttp-two-way-send-response-responds-with-an-empty-message-a

https://support.microsoft.com/en-us/help/4020020

Before BizTalk 2013 and upper version release, BizTalk was not communicating with REST Services without adding custom coding at pipeline level.

For older Version of BizTalk to communicate with REST Service you can refer the below reference:

https://social.technet.microsoft.com/wiki/contents/articles/2474.invoke-restful-web-services-with-biztalk-server-2010.aspx

 

Following five HTTP methods are commonly used in REST based architecture.

  • GET – Provides a read only access to a resource.
  • PUT – Used to create a new resource.
  • DELETE – Used to remove a resource.
  • POST – Used to update existing resource or create a new resource.
  • OPTIONS – Used to get the supported operations on a resource.

Generate an XSD schema for JSON message

You can Refer to below link:

https://msdn.microsoft.com/en-us/library/dn789171.aspx

Create pipelines to process JSON messages

Receive Pipeline:

We are using JSON decoder pipeline component in Receive Pipeline to convert json to xml format. This pipeline has two properties (if you have installed above define hotfix then three properties)

As mentioned in below screenshot.

jsondecoder.jpg

Below property details should be defined.

Add Message Body For Empty message: By default its False, we need to make this true to handle empty message. (This property only available when you have installed above defined hotfix).

Root Node: Define the schema root node name of the schema which is created through JSON Schema Wizard

Root Node Namespace: define the namespace of the schema which is created through JSON Schema Wizard.

Send Pipeline:

For sending json file from BizTalk, we can use the JSON encoder pipeline component. This component converts xml to json file. There is only one property in this pipeline component as defined in below screenshot.

jsonencoder.jpg

Remove Outer Envelope: By default, this property is defined False. When we make it true then its remove top layer or envelope of json file.

Example:

Json file with property Remove Outer Envelope as False:

{

  “TestRequest”: {

    “Test”: {

      “TestRequire”: true

    }

  }

}

Json file with property Remove Outer Envelope as True:

{

  “Test”: {

    ” TestRequire “: true

  }

}

For more info you can refer to below reference:

https://msdn.microsoft.com/en-us/library/dn789172.aspx

These are the prerequisites knowledge about how to deal with Rest-service through BizTalk.

Now in next blog we have defined that how to publish BizTalk as REST Service.

https://vkbiztalk.wordpress.com/2017/06/17/publish-biztalk-as-rest-service/