Consuming webservices from within BizTalk

BizTalk 2006 allows some really good interacting with webservices. If it is a simple webservice, we can very well consume it by adding a reference to it and then consuming it using the orchestrations. Here are some interesting scenarios that I encountered when dealing with webservices.

 

Can I consume the service?

Although Biztalk offers fairly good support for consuming webservices, there are some considerations that might affect the way these interactions are developed. 

For instance, the Add Web Reference feature in BizTalk does not understand the import element in the WSDL. Multi dimensional arrays are not supported from within BizTalk & so on. An elabortate list of these considerations can be  found here.

In some cases, you might run into one of these limitations - most probably when using non .net webservices. There can be a couple of ways in which we can deal with this scenario. This webservice call can be either wrapped within a .Net component or a webservice that can in turn be consumed by BizTalk.

 

Using SOAP Headers when consuming the webservice

When consuming a webservice with SOAP headers, the headers need to be written to the context of the web request message. In order to consume these webservices from within an orchestration We need to promote a property with same name as the SOAP Header & assign it to the message context. To achieve this, create a new property schema with target namespace as https://schemas.microsoft.com/BizTalk/2003/SOAPHeader. Each root element in this schema must match the name in the defined SOAP Header. Also, each root element that corresponds to the SOAP header should have its "Property Schema Base" property set to "MessageContextPropertyBase". Setting this property ensures that the element is visible in the list of elements in the message context.

Once done, then this property can be used in the expression editor to set the property on the request message as -

 

myWebserviceRequestMsg(MyPropSchemaName.MyHeaderName) = "<?xml version='1.0'?> <MySOAPHeaderName xmlns='https://SOAPHeaderSchemas.MyHeader'> <HeaderInfo>abcxyz</HeaderInfo></MySOAPHeaderName>"

 

The myWebserviceRequestMsg can now be sent directly to the webservice along with the associated SOAP Header.

 

Using Webservice request & response messages in Mapper

Most of the times, you need to resort to transformation either for the request message - before sending to the webservice or the response message after recieving from the service. In atrading sceanrio, where the trader hosts the suppliers catalog, the orchestration would need to get the catalog from the webservice & then use the transformation to include catalog in the traders database. However, if you are thinking of creating the map directly by adding a new map, the mapper UI does not allow specifying the webmessages as source or desctination parameters.

To overcome this, we can simply use the transform shape to create a new map for us. Specifying the web response message as the input to the transform shape allows it to create a new map with the web response schema. So instead of creating a new map, just drop a transform shape in the orchestration, create two message - one with the web response schema & other of your destination schema. Open the transformation configuration page & just select new map option there. After specifying your source & destination message, a new map will be created by using those schemas.

 

Hope this alleviates some blues for anyone trying to deal with webservices from BizTalk.

--Sanket