In this article, I shall try to explain how to work with FILE Adapter in BizTalk Server 2006 R2. To explain this I shall take a simple example to take input as FirstName and LastName and output as FullName.
To achieve this, I shall have following things in my BizTalk Server application:
My purpose of this example is to receive input as xml file having FirstName and LastName as two separate xml node and output as xml file having one node Full Name (concatenating First Name and Last Name).
To do that Create a new project in Visual Studio 2005 and select BizTalk Projects > Empty BizTalk Server Projects.
Right click the project and add new item as Schema files > Schema and name as SourceSchema.xsd. The structure of source xml file (input) will be in line with the this .xsd file. Let’s see the structure of this file. You need to right click the parent node and click Insert Schema Node > Child Field Element to create following structure.
<?xml version="1.0" encoding="utf-16" ?>
- <xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns="http://BizTalk1sttest.SourceSchema" targetNamespace="http://BizTalk1sttest.SourceSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema">
- <xs:element name="Request">
<xs:element name="FirstName" type="xs:string" />
<xs:element name="LastName" type="xs:string" />
The Sample source xml file
Get solutions of the .NET problems with video explanations, .pdf and source code in .NET How to's.
Create another xsd file and name it as DestinationSchema.xsd. The structure of destination xml file (output) will be in line with this .xsd file. Let’s see the structure of this file.
<?xml version="1.0" encoding="utf-16" ?>
- <xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns="http://BizTalk1sttest.DestinationSchema" targetNamespace="http://BizTalk1sttest.DestinationSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema">
- <xs:element name="Response">
<xs:element name="FullName" type="xs:string" />
The sample destination file
<?xml version="1.0" encoding="utf-8"?><ns0:Response xmlns:ns0="http://BizTalk1sttest.DestinationSchema">
So, till now we have our Source and Destination schemas ready. Now let’s create a mapping between them. Right click the project > Add new item…. > and add a Map file named SchemaMapping.btm. In the left (Source) and Right (Destination) schema select SourceSchema.xsd and DestinationSchema.xsd from BizTalk Type Picker > Your Project Name > Schemas respectively.
Once you have selected both schemas, your Map file should look something like above image. Note that our requirement is to concatenate FirstName and LastName. To do that drag “String Concatenate” tool from “String Functoids” toolbar (left side). Map the schema nodes as described in the above picture. Double click “String Concatenate” icon (red icon in the center). You will get a Configure Functoids Input dialogue box like below.
Click on second icon from the left side (red and yellow) and write a blank space (press space key from your keyboard). Click OK button. This will keep a space between FirstName and LastName in the output xml file to make it Full Name.
Now let’s move to the very important part of this application. Right click the project > New item … > and add an Orchestration file named FileSystemOrchestration. From the left panel, Drag a Receive and Send tool.
Create two messages named msgReceive and msgResponse from Orchestration View as displayed in the picture below. See the Properties pan of messages. Click on Message Type dropdown and select SourceSchema and DestinationSchema from the Schemas under dropdown for msgReceive and msgResponse respectively.
Now drag Receive tool from the BizTalk Orchestrations toolbar (from the left side). Look at the Properties panel and do following (Look at the picture below for Orchestration View)
For Activate – select True
For Message – select msgReceive
Drag Send tool from BizTalk Orchestration toolbar and look at the Properties panel and do following
For Message – select msgResponse
Now drag Construct Message tool from the toolbar and place in between Receive and Send icon. Look at the Properties pan of Construct Message and do following.
For Messages Constructed - select msgResponse.
Drag a Transform tool from the toolbar and place inside the ConstrctMessage tool as displayed in the above picture. Look at the Properties pan of the Transform tool and do following.
For Input Messages - click on … button, you will get a Transform Configuration dialogue box something like below.
Select Existing Map and from the dropdown select the map we had created earlier (SchemaMapping). Click on Source in the left box and click on the Variable Name column and select msgReceive, click on the Destination in the left box and click on the Variable Name column and select msgResponse.
Cool, our BizTalk application is almost complete, it’s time to Deploy it. In order to deploy your BizTalk application, you need to create a strong name and specify the Application Name. Right click the project and click Properties (It opens the Project Properties dialogue box). Click on Assembly in the left box and scroll to bottom in the right box and click on Assembly Key File. Select a Strong Name key file. To generate a strong name key file, follow below steps.
Open Visual Studio command prompt and enter following command
sn -k NameOftheStrongNameFile.snk
A .snk file will be generated, you need to select this file as the Assembly Key File.
Now explore the Configuration Properties from the left box and click on Deployment, in the right box click on Application Name and specify your application name (in my case “BizTalk1stTest”). Click OK.
Awesome !, now right click the project and click Build. Once the build is successful, again right click the project and click Deploy. Once the deployment is successful you are good to go ahead with configuration.
Open BizTalk Server 2006 Administration Console from Start menu > BizTalk Server 2006. Explore the BizTalk Server 2006 Administration > BizTalk Group > Applications and notice that your application “BizTalk1stTest” is there. Explore it and right click Receive Port and select New One Way Receive Port …. A dialogue box will appear, keep everything default here and click on Receive Location from the left box. Click on New … from the right side box (near Receive Locations label). You will get a dialogue box something like this.
Select FILE from Type dropdown and BizTalkServerApplication (your default BizTalk Server instance) from the Receive handler dropdown. Select XMLReceive from the Receive pipeline dropdown.
Now click on Configure beside Type dropdown. In the Receive folder box, specify input folder name (where you want to drop the input xml file), let’s say C:\BizTalkTest\input. Click OK, OK and return back to main window.
Now right click Send Port and select New > Static One-Way Port …, you will get a dialogue box like below
Select FILE from Type, BizTalkServerApplication (default BizTalk Server instance) from Send Handler dropdown, and XMLTransmit from Send Pipeline dropdown. Click Configure from this dialogue and enter destination folder, let’s say C:\BizTalkTest\output. Click OK, OK and return back to main screen.
Now click on Applications from the main window in the left panel, right click your application from the right panel and click Start. Click on Options >> button and ensure that all checkboxes are checked and click Start. This should start your BizTalk Server 2006 application.
If everything goes well, your BizTalk Application is ready to serve you. Now let’s create an xml file in line with the SourceSchema.xsd that we need to drop into input folder specified above. Go back to your BizTalk application in Visual Studio and right click SourceSchema.xsd and click Generate Instance, this will create a sample xml file in line with the SourceSchema.xsd file. You can modify the data inside it to make it meaningful.
Before we place this file into input folder, we need to do some configuration setting for input and output folder. Right click input and output folder specified above and go to Properties, select Security tab. Ensure that BizTalk Server user account is in the Group or user names box and having Full Control access, if not add BizTalk Server user account and assign Full Control to it (See this article for more configuration related issues http://www.dotnetfunda.com/articles/article274.aspx).
Now, drop the sample xml file into input folder and wait for a minute or two. You will see that a xml file from input folder will be deleted and a new xml file will be placed in the output folder that will have FullName tag with your data.
Hope this journey was useful in learning working with FILE Adapter in BizTalk Server 2006 R2. Thanks and please let me know if you have any question or feedback related with this article.