Tuesday, February 12, 2008

Copy Any-Element to a typed structure

Situation:I received a SSDN reply, the schema contained a element.
This element can contain different other xml data, depending on the request.
I need to map the content of the element to a structured format.

Schema of the incoming XML file (with the element):


Schema of the Output-Xml, this schema = the structure within th element


Problem:
BizTalk can’t link elements, the Mass copy didn’t work as there are more fields next to above the any-element at the same level. (See XSD schema)

Solution:
Add a Message Assign shape to your Orchestration
Add the following code


IdentifyPersonResultMsg = xpath(SSDNReplyMsg, "/*[local-name()='SSDNReply']/*[local-name()='ServiceReply']/*[local-name()='IdentifyPersonReply']");



I just use an xpath query to get the content in the element and I place the result I the correct message.
In this case IdentifyPersonResultMsg has the message type as the element

Message constructed on the Construct Shape: IdentifyPersonResultMsg

Wednesday, February 6, 2008

Uploading Documents to a SharePoint Document Library containing different Content Types

Situation:
A document library in SharePoint contains several Content Types. BizTalk will upload documents to the document library in SharePoint.
When uploading via BizTalk the document to SharePoint, I need to say which Content Type the document is linked too.

Problem:
When uploading the document and adding the Metadata needed for the content type of the document, I saw that SharePoint always uses the default content type.
So metadata not used in the default content type is discharged.
How can I tell the WSS adapter which content type to use?

Solution:
The solution is very simple; the name of the content type is also metadata.

In the orchestration, add a Message Assign Shape
Add the following code to the Message Assign Shape:

SharePointOutMsg(WSS.ConfigPropertiesXml) = "<ConfigPropertiesXml><PropertyName1>Content Type</PropertyName1><PropertySource1>My Custom ContentType</PropertySource1> [Add more custom metadata] </ConfigPropertiesXml>";

Tuesday, February 5, 2008

Creating an 0kb File

Situation:
For a project I needed to create an XML file and also a 0kb Control file.
This 0Kb file is needed for the external software to know for sure when the Xml file is created. Only when the 0Kb file is available, the external software will read the Xml file.
This situation is still frequently used in the environment I work (Mainframe, old VB6,….)
A Some Microsoft consultant told us to create an custom pipeline and did some custom coding.

Problem:
How to create an 0Kb file with BizTalk without creating a custom pipeline with custom code.

Solution
Create a Flat File Schema, called CrtFile




Set the following schema parameter:
Default Child Delimiter Type: none
Default Escape Character Type: none
Default Pad Character Type: none
Default repeating Delimiter Character Type: none
Default Wrap Character Type: none




Set the following properties on the root node:
Child Delimited Type : none
Child Order: infix
Escape Character Type: none
Nillable: true
Preserve Delimiter for Empty Data: No
Suppress Trailing Delimters: No





Create a Flat File Send Pipeline
Add the Flat File assembler to the Assemble Block.




In the Orchestration,
Add a message assign shape and add the following code

//-- Initialize the CrtFile Variable --
tempXmlDoc = new System.Xml.XmlDocument();
tempXmlDoc.LoadXml("<?xml:namespace prefix = ns0 /><ns0:root ns0="http://My0kbProject.Schemas.CrtFile"></ns0:root>");

zeroKbMsg = tempXmlDoc;


When sending the zeroKbMsg to the File Adapter, using the FlatFileSendPipeline, you will have an 0kb file created.

Monday, February 4, 2008

Receiveing a File from a File or Ftp Adapter

Situation:
I have an orchestration, receiving an XML-file from via the File Adapter. I need the filename to store in a database.
When placing the project in the production environment, we decided to use the FTP adapter instead of the File Adapter.
With BizTalk, It should be easy to change the receive ports.

Problem
I used in my orchestration line of codes like ReceiveXmlMessage(FILE.ReceivedFileName), but when changing the File Adapter to FTP adapter in the BizTalk Administration Console, something went wrong.

Solution
- Create a variable: fileName in your Orchestration
- Add an Expression Shape to you Orchestration
- Add the following Code into the expression shape:

tempString = "UNKNOWN";
if(FILE.ReceivedFileName exists ReceiveXmlMessage)
{
fileName =ReceiveXmlMessage(FILE.ReceivedFileName);
}
else if(FTP.ReceivedFileName exists ReceiveXmlMessage)
{
fileName =ReceiveXmlMessage(FTP.ReceivedFileName);
}

Not working Solutions:
I thought the following code would work, but I received an error saying that ReceiveXmlMessage(FTP.ReceivedFileName) was empty while using the File Adapter.

Not working code:
fileName = ReceiveXmlMessage(FILE.ReceivedFileName) + ReceiveXmlMessage(FTP.ReceivedFileName)