Saturday, December 11, 2010

BizTalk Server Tutorial Part 5: Map

Continuing the application of Part4
Create the following additional folders:
1.    C:\BizTalkServerTutorial\FileDrop\TrackingApplication
Charan: We have a tracking application to keep record of all the loan applications received, but this application expects input in the following XML format.
<Request xmlns="http://TrackingApplication">
<SSN></SSN>
<Name></Name>
<Amount></Amount>
</Request>
So we can’t route a copy of the original message and it expect this input at this folder location ‘C:\BizTalkServerTutorial\FileDrop\TrackingApplication’ as XML file.
Rohit: Don’t worry BizTalk provide you maps to transform message from 1 message format to another. But for that you need to specify the format of the message by creating a schema.
Create the schema for Tracking application input XML
Open the BizTalk project ‘BizTalkTutorial.Part4’(Created in Part4 of this tutorial series) in Visual Studio 2010.Right click the ‘BizTalkTutorial.Part4’ and choose ‘Add -> Add New Item
Choose ‘Schema’ from ‘Schema Files’ and give ‘TrackingApplicationInputSchema.xsd’ as the name of the schema. Click Add button.
Rename the ‘Root’ in the generated schema to ‘Request’ and choose the ‘<Schema>’ node to change the ‘Target namespace’ to ‘http://TrackingApplication’ as shown below
Right click the ‘Request’ node and add the ‘Child Field Element’ as shown below. Rename it from ‘Field’ to ‘SSN’.
Similarly add two more ‘Child Field Element’ and rename them as ‘Name’ and ‘Amount’. Then change the ‘Data Type’ for ‘Amount’ from ‘xs:string’ to ‘xs:int’ as shown below
Next select the ‘TrackingApplicationInputSchema.xsd’ and in the Properties of this schema, set ‘Output Instance Filename’ to ‘C:\BizTalkServerTutorial\FileDrop\TrackingApplicationInput.xml
Next right-click the ‘TrackingApplicationInputSchema.xsd’ and choose ‘Generate Instance’.
It would generate an XML file ‘C:\BizTalkServerTutorial\FileDrop\TrackingApplicationInput.xml’. The content of this XML should be something similar to
<ns0:Request xmlns:ns0="http://TrackingApplication">
<SSN>SSN_0</SSN>
<Name>Name_0</Name>
<Amount>10</Amount>
</ns0:Request>
Now create a Map
Right click the ‘BizTalkTutorial.Part4’ and choose ‘Add -> Add New Item
Choose ‘Map’ from ‘Map Files’ and specify ‘LoanRequest_To_TrackingApplicationInput.btm’ as name of the map.Next click ‘Open Source Schema’ and choose ‘BizTalkTutorial.Part4.LoanRequest’ from ‘BizTalk Type Picker’ dialog box.
Click ‘Open Destination Schema’ and choose ‘BizTalkTutorial.Part4.TrackingApplicationInputSchema’ from ‘BizTalk Type Picker’ dialog box.
In mapper editor click ‘SSN’ in ‘LoanRequest’ schema and drag it to ‘SSN’ in the ‘TrackingApplicationInputSchema’. Similary do for the ‘Amount’ field.
In mapper editor drag ‘String Concatenate’ functoid. Then drag ‘FirstName’ field from ‘LoanRequest’ schema to it and then drag the ‘LastName’ field from ‘LoanRequest’ schema to ‘String Concatenate’ functoid. At last drag the ‘String Concatenate’ functoid to the ‘Name’ field in the ‘TrackingApplicationInputSchema
Next select the ‘LoanRequest_To_TrackingApplicationInput.btm’ and in the Properties of this map set ‘TestMap Input’ to ‘Native’ ‘TestMap Input Instance’ to ‘C:\BizTalkServerTutorial\FileDrop\App1Output.txt’ (Create in Part4 of this tutorial) and ‘TestMap Output Instance’ to ‘C:\BizTalkServerTutorial\FileDrop\MapOutput.xml’.
Next right-click the ‘LoanRequest_To_TrackingApplicationInput.btm’ and choose ‘Test Map’.
It would generate an XML file ‘C:\BizTalkServerTutorial\FileDrop\TrackingApplicationInput.xml’. The content of this XML should be something similar to
<ns0:Request xmlns:ns0="http://TrackingApplication">
<SSN>BMTP2000E</SSN>
<Name>NitinSachdeva</Name>
<Amount>50000</Amount>
</ns0:Request>
Next redeploy this solution and you must see the deployed map in the ‘BizTalkServerTutorialApplication’ as shown below
Next create a send port using the following details
Name: SP_TrackingApplication_FILE
Transport Type Adapter: FILE
Destination Folder: C:\BizTalkServerTutorial\FileDrop\TrackingApplication
Send pipeline: PassThruTransmit
In the ‘Outbound Maps’ tab select the map ‘LoanRequest_To_TrackingApplicationInput’ as shown below
Next create the ‘Send Port Group’. Specify the name of ‘Send Port Group’ as ‘SendPortGroup_RoutrLoanApplications’ and select both the send ports as part of this ‘Send Port Group’.
Go to filter tab and specify filter as ‘BTS.ReceivePortName == RP_SourceApplication’.
Remove the filer created for send port SP_DestinationApplication_FILE’ in part 2 and start both the send ports, after that start the Send port group and test the solution by putting a copy of file ‘C:\BizTalkServerTutorial\FileDrop\App1Output.txt’ in folder ‘C:\BizTalkServerTutorial\FileDrop\SourceLocation’.

Note: You have to restart the host instance so that the changes made to the deployed solution can take in affect.
Summary
You have seen
    How to create an XML schema.          
    How to create a sample file complying with schema.
    How to create and test map.
    How to use mapper at the send port.
    How to create send port group

 Cheers,
Rohit Sharma

9 comments:

Anonymous said...

Nice tutorial... finally something understandable on it's own. You need to remove the filters on the send locations after adding the port send port group to avoid duplicated messages to the main application.

Anonymous said...

I had to restart the host instance after redeploying the solution since it had already loaded the older assembly, and only at that point were I able to have the messages end up in the tracking application output folder.

Anonymous said...

A very nice tutorial same as you can find on MSDN!

Anonymous said...

very help full and innovative blog for biztalk
thanks for this.

Here I have one very basic question for biztalk Pleae provide me some information for enlist? What is actual purpose of enlit and when it can be use?

Rohit C.M. Sharma said...

The BizTalk works using pub-sub pattern as shown in part 3. When you enlist some artifacts(send post, orchestration or parties in role link) the subscription get created. For detail on how to create subscription refers to part 6. When you enlist e.g. a send port then a subscription with the properties you defined in the filter (when creating send port) get created. You can think of a subscription as some entries in BizTalk database and whenever any message get received BizTalk engine checks the context properties of the message against these subscriptions to find out who(send ports, orchestrations etc.) is interested in receiving a copy of this message.

Rohit C.M. Sharma said...

I have incorporated the 2 point mentioned in the comment regarding filter and restart of host instances. Thanks for reporting.

Anonymous said...

I get following error

A message sent to adapter "FILE" on send port "SP_TrackingApplication_FILE" with URI "D:\BizTalkServerTutorial\FileDrop\TrackingApplication\TrackingApplicationInput.xml" is suspended.

Unknown said...

Thanks for the lesson and it is quite innovative.<a href="http://www.createhtml5map.com/”>Create HTML 5Map</a>

radha said...

Nice post .Keep sharing Biztalk online course

Post a Comment