In my last project I had a requirement where we will be getting multiple records in a single file, and we have to loop through the file to get a single record and process it. I got a very good article on this written by Jan. Thanks Jan.
When I was trying to implement the tutorial provided by Jan, I faced a few silly problems, obviously because of my lack of knowledge. So, I thought of putting the same, in a more simpler way.
So, we will take the same example to develop our tutorial where we have the customer information containing the
Name and this information will come to us as a batch file under customers node.
We will execute the following steps to implement this tutorial:
- Create document schema.
- Create envelop schema.
- Test XML file against schemas.
- Create receive pipeline which will bread the batch into individual requests.
- Create receive and send port and shape.
Create document schema
- Start a new empty BizTalk project and add a new schema, as CustomerDocument.
- Change the name of the root node to
- Add the
Name properties as the child field elements to the schema.
Note: Make sure that the schema looks similar to the above image, for me it created problems. The point is to set
xs:string as “Data Type” property and not “Base Data Type” property.
Create envelop schema
- Let’s add a new schema to the project and name it “CustomersEnvelope”.
- Identify the new schema as an envelope by selecting the schema node and changing the
Envelope property to
Yes in the Properties window.
- Change the name of the root node to
- You can import the document schema into the envelope schema by clicking on the ellipsis button for the
Imports property of the schema node. You’ll get a dialog window in which you can add an “XSD Import” of the CustomerDocument schema. Then add a new child record node under the
Customers node and name it
Customer. Set the Data Structure property of this new node to “ns0:Customer”. (If you haven’t changed the namespace: If you don’t like ns0 notation, and want to put proper notation, use “ab|” tag provided in the import dialog. See the image shown below for more details.)
Note: If you don’t want to use an XSD Import, you can set the Data Structure property to “xs:anyType”. When you say “xs:anyType” it will remove the child nodes. That is why, this way is not preferable as it will increase the complexity.
- Change to “Body XPath” property of the
Customers node by clicking the ellipsis button and point to the
Customers node. The property will be set to: /*
[local-name()='Customers' and namespace-uri()='http://XMLSplitExample.CustomersEnvelope']
Note: Make sure that your
xPath is exactly similar to the one given above, by default it will append some other code also.
Test XML file against schemas
So now we have created the perfect document as well as the envelop schemas. If you want to make sure before going further you can use the utility called xmldasm.exe which can be found in <sdk>\Utilities\PipelineTools folder. From here you can copy the xmldasm.exe and PipelineObjects.dll files to your working folder and execute the following command at command prompt:
xmldasm batch.xml -ds customerdocument.xsd -es customerenvelope.xsd
If everything is fine, then you will get a separate file for each record given in batch.xml file.
You can also use IDE to generate valid XML file for you from the schema using the following steps:
- Right click on customerenvelop.xsd file, go to property and set “Output Instance FileName” to Batch.xml file.
- Again right click on customerenvelop.xsd, select Generate Instance from the menu.
Create receive pipeline
Next you need to configure a new
ReceivePipeline in which the schemas created above will be used:
- Add a new
ReceivePipeline to your project and name it
- Add an XML disassembler to the disassemble stage of the
- Set the Document schemas property of that XML disassembler to the CustomerDocument schema.
- Set the Envelope schemas property of the XML disassembler to the CustomersEnvelope schema.
Create receive and send port and shape.
CustomersReceivePipeline can be used in an orchestration; so let’s do that:
- Add a new orchestration to the project, name the orchestration as
- Add a port to the orchestration.
- Once you add a port to Port Surface Area, it will open the port configuration wizard as shown below:
Click on Next and provide the port name as
ReqPort and click Next which will take you to the following screen:
Enter the details given above and click Next. This will take you to the following screen where we will configure the pattern of port like, type of port
send and specify the listening port, see the screen shown below for more details:
Note: Note that we have to specify the
CustomerReceivePipeline we created above as the receive pipeline.
In a similar way, we can create the sending port with the direction “I’ll always be sending messag…” and receive pipeline as “XMLTransmit”. Refer to the screen below:
Note: If you want to send the data to SQL database for insertion then you have to bind the port later. May be I will discuss this in my next tutorial.
- Now we will add a receive shape to the orchestration that receives a message of the CustomerDocument schema type.
- Similarly we will add send shape to the orchestration that sends a message of the CustomerDocument schema type to send port configured earlier.
- Once everything is set, we can compile and deploy the orchestration to the BizTalk server.
Hope this tutorial will help you to develop your cool orchestration. If you need any further help do mail me at firstname.lastname@example.org.