Message Debatching inside Biztalk Orchestration, with TargetNamespace

Published on : Dec 18, 2006

Category : BizTalk Server

Saravana

Author

You can download the entire article as a PDF document. Message Debatching inside Biztalk Orchestration, with TargetNamespace
Recently I end up in a scenario where I need to debatch a message inside the orchestration to produce multiple messages based on XPATH. There are already quite few articles about it, one good one is from Stephen Thomas hands on lab. Only problem with this lab is, the examples are based on schemas without any TargetNamespace. In a real world situation its hard to imagine a schema without a TargetNamespace, so I spend some time to enhance the sample with TargetNamespace. I’ll highlight some of the things you need to take care when using schemas with TargetNamespace. Download: The attached zip file contains the complete BizTalk Solution. follow the steps below to configure it: 1. Extract the sample BizTalkDebatching to C:BTSSamples 2. Open the project in visual studio, build and deploy it. (Don’t need to create the ports, since early binding is used) 3. Open Biztalk Administration console and set the appropriate BizTalk host instance for Orchestration 4. Drop the sample file (found under BizTalkDebatchingFileDropsSample File) into the folder FileDropsMD_In 5. You should see 10 messages under MD_OutAfter Mapping and 10 messages under  MD_OutBefore Mapping Its quite straight forward to understand, if you have any doubts, read this article for explanation.

1. Set TargetNamespace

Make sure all your schemas has appropriate TargetNamespace, in general its very important to have a TargetNamespace, because BizTalk identifies the message based on the combination of TargetNamespace#RootElement combination.

2. We need to include namespaces in the XPath.

Any XPATH we use inside the orchestration must be fully qualified with the local name and namespace uri (TargetNamespace we set in the schemas) as shown below. nRecordCount = System.Convert.ToInt32(xpath(Input, “count(/*[local-name()=’EnvelopeData’ and namespace-uri()=’http://www.digitaldeposit.net/samples/schemas’]/*[local-name()=’Data’ and namespace-uri()=’http://www.digitaldeposit.net/samples/schemas’])”));

3. When looping through the nodes, we need to use xpaths node-set function position() .

When we are extracting the sub message from the envelope message we’ll be extracting it based on the position inside a loop. We can make use of XPATH Node-set function position() to get to the sub message as shown below sXPath = System.String.Format(“/*[local-name()=’EnvelopeData’ and namespace-uri()=’http://www.digitaldeposit.net/samples/schemas’]/*[local-name()=’Data’ and namespace-uri()=’http://www.digitaldeposit.net/samples/schemas’ and position()={0}]”, nLoopCount);

4. Set Schemas “ElementFormDefault” property to Qualified (default is unqualified)

When elementFormDefault is set to qualified, it implies that all the elements must be explicitly qualified, either by using a prefix or setting a {default namespace}. An unqualified setting means that only the globally declared elements must be explicitly qualified, and the locally declared elements must not be qualified. Unfortunately the default setting for elementFormDefault is unqualified. If you don’t set the elementFormDefault value to Qualified the output will be as shown below without any values. <?xml version=”1.0″ encoding=”utf-8″?> <ns0:MappedData xmlns:ns0=”http://www.digitaldeposit.net/samples/schemas”> <Id></Id> <Company></Company> <FName></FName> <LName></LName> <OrderId></OrderId> <RecDate></RecDate> <ShipDate></ShipDate> </ns0:MappedData> Once after setting the elementFormDefault to Qualifed, you’ll get the required output. <?xml version=”1.0″ encoding=”utf-8″?> <ns0:MappedData xmlns:ns0=”http://www.digitaldeposit.net/samples/schemas”> <ns0:Id>3</ns0:Id> <ns0:Company>City Power And Light</ns0:Company> <ns0:FName>Greg</ns0:FName> <ns0:LName>Chapman</ns0:LName> <ns0:OrderId>12031-ABC-0001</ns0:OrderId> <ns0:RecDate>5/15/2005</ns0:RecDate> <ns0:ShipDate>5/17/2005</ns0:ShipDate> </ns0:MappedData>
You can download the entire article as a PDF document. Message Debatching inside Biztalk Orchestration, with TargetNamespace
[adrotate banner=”3″]