While working on a pipeline component I encountered a very strange behavior of XML disassembler. I had few promoted properties which I was trying to access in a pipeline component in Validate stage after the execution of XML Disassembler. As we all know that the Pipelines are executed in sequential manner and the output of one pipeline component is used as input to the next one in the sequence(except in Disassemble stage). ( Read more- Understanding Pipeline Execution). So, ideally after execution of XML Disassembler, Promoted Properties should be accessible in later stages. But shockingly there value was NULL. Now let’s have a look into my sample BizTalk application for better understanding. I have a simple schema in which both the properties are promoted- Emp & Property Schema Image I created a simple pipeline component where I tried to read values of ID and Name from message context using below code and later promoted “ReceiveFileName” Fetching Promoted Properties in Pipeline Component Image Created a simple Custom Receive Pipeline with XML Disassembler and later used my pipeline component in Validate Stage. Receive Pipeline Image But strangely when I tried to fetch the promoted properties found out that it’s returning NULL as shown below. Promoted Properties as NULL in Pipeline component Image Cause:- After some research got to know that it’s a known behavior. Basically, the XmlDisassembler does not read through the incoming message immediately. It waits until some later component or the MessageBox reads it. This is done for various performance reasons like memory consumption, etc. So, since my custom pipeline component is next in line, when it gets the Message, data has not yet been read by the XmlDisassembler even though it passed that Stage in the Pipeline, so it hasn’t had a chance to Read and Promote any Context Properties. This is by design, and what you are seeing is a known side-effect. Its accomplished by wrapping the data in a custom Stream class. That is why it only gets read and processed when some other component reads it. Solution/Workaround:- The easiest option would be to just do you work with the Properties in an Orchestration. If you absolutely have to use a Pipeline Component, then you will have to somehow force a Read by the XmlDisassembler. For example in our pipeline component we have read the values using below code and forced a Read/Promote by the XmlDisassembler. //Reading message data using XML Document. System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument(); xmlDoc.Load(originalStream); Using XMLDoc can have performance implication as the complete message will be loaded in memory, so you can use the below code as well. //Reading message data using Stream, this will not have any performance implication. System.IO.MemoryStream ms = new MemoryStream(); originalStream.CopyTo(ms); ms.Position = 0; inmsg.BodyPart.Data = ms; As shown in below image. Promoted Properties containing Value After performing Forced Read by XML Disassembler Image Check the discussion over the same issue- XML Diassembler component is not doing property promotion Hope it helps. Download the sample application from here. Word version of this blog is here.
@Gmail, @Facebook , @Twitter, @LinkedIn , @MSDNTechnet, @My Personal Blog
6 thoughts on “Very Strange behavior of XML Disassembler- Property Promotion not happening properly”
Nice write-up. Thanks for sharing this strange behavior. BTW can you please also share your research fact, may be MSDN link or any other blog or some video for this strange behavior?
Thanks for your appreciation.
I couldn’t find any article which talks about this behavior, it’s my observation.
However, you can have a look into the below discussion-
Also, if possible you can have a look into the sample(solution) shared and let us know your findings.
One of the reader suggested to make ValidateDocument = True in XMLDisassembler and perhaps this will perhaps force Disassembler to promote the properties.
Made the changes but still getting values as NULL only.
Check the below screenshots
Receive Pipeline with ValidateDocument=True Screenshot-
Pipeline Comp Screenshot-
Hi Prashant, this is expected behaviour. It is true that pipeline components are executed in sequence, but in a streaming manner. When message is flowing through your custom component it is also flowing through the XmlDisassembler at the same time. Wait till the message reading is finished and then access the promoted properties in your custom component. Encapsulating the original data stream in CForwardOnlyEventingReadStream and put your custom code inside AfterLastReadEvent event. You can find an example in “Professional BizTalk Server 2006” book (page 127) in google books. I’m pasting a link as I can’t simply copy and paste the code from there https://books.google.nl/books?id=qr3i1qiMwJ8C&pg=PA127. I hope it helps.
LikeLiked by 1 person
Thanks a lot for sharing your insight and the code.
Do you know any article/link which talks about similar behavior of XML Disassembler?
I have just finished writing a blog-post on exactly this same finding. I ran across this problem a fortnight ago, and managed to debug it today. It all makes sense, but it’s a tricksy little thing to work around. Essentially to get access to properties which might be promoted by the disassembler component, you may end up compromising the efficiency of the streaming model.
My solution is to seek to the end of the message and back again. But you must ensure that you don’t have a forward only stream at that point.
LikeLiked by 1 person