Geeks With Blogs
Pseudo Knowledge Base Useful stuff I've collected... Enjoy.
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_-- Posted on Thursday, November 27, 2008 10:10 PM BizTalk , Coding | Back to top


Comments on this post: BizTalk: Receiving Multi Part Messages

# re: BizTalk: Receiving Multi Part Messages
Requesting Gravatar...
Nice Article.

I am trying to work with nested MIME multipart messages.

Do you have any idea about, How deal with nested MIME messages.
Left by David on Jan 13, 2009 8:16 AM

# re: BizTalk: Receiving Multi Part Messages
Requesting Gravatar...
After working through all the problems I had getting the code to work with the MIME adaptor I'd look at creating a custom component that did everything. It sounds harder than it is.
In my case getting the Multi part message to process was only the first hurdle. After that I need to get the MIME component to consume the 'non-MIME' message. To do that I created a custom component to modify the header information to make the message appear as a MIME message. At the end of the day I could have assigned the message parts in the same code and saved my self alot of effort. Next time!!
Just get a sample component project and modify the message as I had to do. I have posted the code I wrote to modify the multi part message in this blog post 'http://geekswithblogs.net/PsudoKnowledgeBase/archive/2009/01/13/problems-receiving-a-multi-part-message-via-a-http-vs.aspx'.
Left by Geordie on Jan 20, 2009 7:55 PM

# re: BizTalk: Receiving Multi Part Messages
Requesting Gravatar...
Hi, I could not file the download sample on the link. Secondaly, I tried using sample message and all the required configuration but I am getting Exception
The MIME decoder cannot find a MIME part for the specified index. The Index was greater than the MIME part count.
Left by Raminder on Jul 09, 2009 9:22 AM

# re: BizTalk: Receiving Multi Part Messages
Requesting Gravatar...
Hi,
Could you reload your sample?
Left by Raminder on Jul 09, 2009 11:03 AM

# re: BizTalk: Receiving Multi Part Messages
Requesting Gravatar...
Not sure why the file is not downloading. It is still on the server. I'll see if I can find it on my computer and post it in a different way.

Geordie
Left by Geordie on Jul 09, 2009 7:41 PM

# re: BizTalk: Receiving Multi Part Messages
Requesting Gravatar...
Thanks for the article. I realize this is a stale thread, but has anyone taken this solution far enough to actually receive the message via HTTP and IIS?

I presume that a HTTP or WCF receive location would be used, but I am having trouble connecting the dots. Can anyone help?

Thank you.
Left by Ken on Feb 01, 2013 8:58 AM

Your comment:
 (will show your gravatar)


Copyright © Geordie | Powered by: GeeksWithBlogs.net