When you call a REST Service in BizTalk 2013, there could be scenarios when an ID, or any other query variable, must be determined at runtime. To enable such scenarios, you specify variables for the HTTP Method URL Mapping. The variable maps normally to a promoted field in a message but there are some scenarios where you cannot use promoted properties.

In this sample I’m going to call a REST Service and update an Event for a specific Customer with BizTalk. To start the process I receive a CustomerEvent message with a Customer Id. Because the REST service expects a data message I have to transform it to the data message and post the data message to the REST service.

 

 

 

 

REST Service called by SoapUI

But also the Customer Id needs to be dynamically set in the URI at runtime. I can’t use property promotion to dynamically set the URI because I don’t have a customer_id field in the data message. So in this specific case I cannot use promoted properties.
To solve this I’m going to put the customer_id field from the CustomerEvent message in a custom context property because I don’t have the customer_id field anymore in the data message.

Steps

The following steps show how you can use variable mapping and context properties without using promoted properties.

Generate schemas for the CustomerEvent- and the data message.
 
Create a Property schema.
 
In the Property Schema Base property you can specify if the property is a Message Data property or a Message Context property.
 
Create a BizTalk Map to transform the CustomerEvent message to the data message.
 
Create an Orchestration to execute the Map and set the custom context property in a Message Assignment shape. (The customer_id is a distinguished field and is not promoted.)
 

Create a Send Port in the BizTalk Administration Console. Specify WCF-WebHttp for the Type option in the Transport section of the General tab.
Also specify variables for the HTTP Method URL Mapping, provide the variable component of the URL within curly brackets { }.

 
Click in the Variable Mapping section on the ’Edit’ button to specify where the value for the variable ID must be picked from at runtime. Under the Variable column, the dialog box lists the variables that you defined for the URL Mapping. In the Property Name field you must specify the name of the property that provides the value to be associated to the variable.
  

 

Conclusion

If you have to call a REST Service with BizTalk and the URI has to be dynamically set at runtime, you normally can use property promotion. However there are scenarios where you cannot use promoted properties and in such cases custom context properties are a really good alternative!

You can download the BizTalk sample with the source code here:
http://code.msdn.microsoft.com/Using-Variable-Mapping-in-2d52d9ef