I have been working on a BizTalk project for a while now and after a bumpy start all has been going well. The current message that we are dealing with is the receipt and processing of a Purchase Order. The processing and mapping of the purchase order to the SAP orders schema went well and all I need to do was to receive the document from the customer. After a bit of a delay in getting an accurate sample message, I set to work on creating a process for receiving a PO from a Ponton server. On examining the sample message I found I was going to need to deal with receiving a Multi Part message.
So I looked at the SDK and searched online but found very little guidance. The samples and discussion where mainly about receiving messages from the POP3 adapter. In our scenario the message will be received by HTTP then dropped to a file. It will then be archived and processed.
How difficult can it be! 4 days latter I can answer the question. It is not easy if you have not dealt with this type of message before. So here is my guidance on this issue.
1. Sample messages. As mentioned the samples that I found were email messages. I was not sure if these samples were relevant to my project. With respect to the message it appears that BizTalk cares about the MIME 1.0, boundary and description declarations. As it happens the message I was receiving was missing all these parts. Also check out this post from Doug -
http://www.tech-archive.net/Archive/BizTalk/microsoft.public.biztalk.general/2006-07/msg00134.html. Unfortunately the final solution was not posted but it helped me get closer to a solution.
2. You will need to make a Multi Part message in your orchestration. This is well covered in blogs and documentation. It is also straight forward. But here is the kicker. When are receiving multi part messages, the order you create the message parts matters!!
Eric did a good job of documenting this ‘undocumented’ feature.
To summarize Eric’s post: The order of the message parts in displayed in VS is alphabetical, but creation order matters and may be different from what is displayed in VS. The message parts need to be created in the order they appear after the message has been split into its parts by the pipeline. The only way to determine the order of creation is to view the orchestration file in a text editor. You can find the message part order by examining the failed message in BizTalk Manager. Drill into the error, go the message tab and double click the message. The message parts should be listed on the left hand side.
If you are getting an
Inner exception: ‘Wrong BodyPartException …’ and ‘Multi-part message has body part ‘XXXXX’, expected body part ‘YYYYYY’, and everything appears to be correct, check this as a possible cause. I lost over a day trying to resolve this issue!
The sample application contains 2 Multi Part messages only the second one works even though they look the same in VS.
3. You will need a custom pipeline. BizTalk uses the MIME component to process multi part messages. Even if the message is not a MIME message it can be processed by setting the ‘allow non MIME message’ property to true. The body part content type field is optional. Valid values are ‘text/xml ‘, ‘application/xml’… etc. The ‘Body part index’ is a 0 based index that identifies the body part by location in the message. It took me a while to discover that I also needed to add an XML dissembler in the pipeline as well. All the message part schemas are added to the ‘Document schemas’ collection.
Tricks that might help:
· Initially type the Multi Part message parts as System.Xml.XmlDocument. This will remove at least one area of possible error. This will allow you to identify other problems and resolve them one at a time.
· View the orchestration file in Notepad. Look for the definition of the multi part message. The order the parts are listed in the XML are the order the message parts were created. Remember creation order matters.
Sample Message
MIME-Version: 1.0
Content-Type: multipart/related; type="text/xml";
boundary="_968002A2-AAE4-43E0-90D3-83461FE91020_"
--_968002A2-AAE4-43E0-90D3-83461FE91020_
MIME-Version: 1.0
Content-Transfer-Encoding: binary
Content-Description: Header
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<eb:MessageHeader xmlns:eb="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd" eb:version="2.0" soapenv:mustUnderstand="1">
... Rest of the Header Message....
</soapenv:Body>
</soapenv:Envelope>
--_968002A2-AAE4-43E0-90D3-83461FE91020_
MIME-Version: 1.0
Content-Transfer-Encoding: binary
Content-Description: POMsg
<?xml version="1.0" encoding="UTF-8"?>
<PurchaseOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="PurchaseOrderV2R30" PurchaseOrderStatusType="Original" PurchaseOrderType="StandardOrder">
... Rest of the Purchase Order Message....
</PurchaseOrder>
--_968002A2-AAE4-43E0-90D3-83461FE91020_--