Discussion:
Getting XML body and context from tracking
(too old to reply)
r***@gmail.com
2007-05-07 13:54:07 UTC
Permalink
Hi,

The question on how to get hold of the XML data from tracking database
(we're then talking about both the XML body and the XML context) gets
asked over and over again without being answered ... A while a ago
Niriven answered on how to decompress the actual message body from the
BizTalkDTADb (see link at the end of this message). As the XML is
compressed the clue is to use a
Microsoft.BizTalk.Message.Interop.CompressionStreams.Decompress method
from the Microsoft.BizTalk.Pipeline.dll - I've tried it and it works
like charm. The only thing to think of is that the CompressionStreams
class is internal in BizTalk 2006 (not in 2004 I think) and that one
has to invoke the Decompress method using reflection (I've added the
code for that at the end of this message).

However the decompression does not work on the context of that message
(stored in the imgContext field)! One only gets an exception from the
DecompressSequentialStream method that is called from the Decompress
method (I've pasted the exception for everyone to read). This means
that it's still impossible to get hold of values like the
InterchangeID or ReceiveLocation for the message that lives in the
context of a message but are not directly in own fields within the
BizTalkDTADb.

It is possible to get the XML data using the
MSBTS_TrackedMessageInstance WMI script but this is slow as the script
only support saving messages to file!

So, basically we can decompress and read the message body stored in
the imgPart field (thanks to Niriven and the Reflector tool) but how
on earth are the data in the imgContext field stored! I've tried
reading it like plain the using the encodings I could think of without
success ... Has anyone tried this before and succeed or failed? Any
information is interesting.

Exception when calling the Decompress method with data from the
imgContext field in BizTalkDTADb:
{System.Reflection.TargetInvocationException: Exception has been
thrown by the target of an invocation. --->
System.Runtime.InteropServices.COMException (0x8000FFFF): Catastrophic
failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
at
Microsoft.BizTalk.Message.Interop.CompressionStreams.DecompressSequentialStream(Stream
rawStream, Stream& compressedStream, UInt32& bytesRead, UInt32&
bytesWritten)
at
Microsoft.BizTalk.Message.Interop.CompressionStreams.Decompress(Stream
stm, UInt32& bytesRead, UInt32& bytesWritten)
at
Microsoft.BizTalk.Message.Interop.CompressionStreams.Decompress(Stream
stm)
--- End of inner exception stack trace ---

Link to post on how to get the XML from the message body:
http://groups.google.se/group/microsoft.public.biztalk.general/browse_thread/thread/599c038807317802/30473829b681de6d?lnk=st&q=imgpart&rnum=3&hl=sv#30473829b681de6d

Code for invoking the
Microsoft.BizTalk.Message.Interop.CompressionStreams.Decompress using
reflection:
Assembly pipelineAssembly = Assembly.LoadFrom(string.Concat(<path to
dll>, @"\Microsoft.BizTalk.Pipeline.dll"));
Type compressionStreamsType =
pipelineAssembly.GetType("Microsoft.BizTalk.Message.Interop.CompressionStreams",
true);
return (Stream)compressionStreamsType.InvokeMember("Decompress",
BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Static,
null, null, new object[] { (object)stream });
r***@gmail.com
2007-06-04 14:33:13 UTC
Permalink
Post by r***@gmail.com
Hi,
The question on how to get hold of the XML data from tracking database
(we're then talking about both the XML body and the XML context) gets
asked over and over again without being answered ... A while a ago
Niriven answered on how to decompress the actual message body from the
BizTalkDTADb (see link at the end of this message). As the XML is
compressed the clue is to use a
Microsoft.BizTalk.Message.Interop.CompressionStreams.Decompress method
from the Microsoft.BizTalk.Pipeline.dll - I've tried it and it works
like charm. The only thing to think of is that the CompressionStreams
class is internal in BizTalk 2006 (not in 2004 I think) and that one
has to invoke the Decompress method using reflection (I've added the
code for that at the end of this message).
However the decompression does not work on the context of that message
(stored in the imgContext field)! One only gets an exception from the
DecompressSequentialStream method that is called from the Decompress
method (I've pasted the exception for everyone to read). This means
that it's still impossible to get hold of values like the
InterchangeID or ReceiveLocation for the message that lives in the
context of a message but are not directly in own fields within the
BizTalkDTADb.
It is possible to get the XML data using the
MSBTS_TrackedMessageInstance WMI script but this is slow as the script
only support saving messages to file!
So, basically we can decompress and read the message body stored in
the imgPart field (thanks to Niriven and the Reflector tool) but how
on earth are the data in the imgContext field stored! I've tried
reading it like plain the using the encodings I could think of without
success ... Has anyone tried this before and succeed or failed? Any
information is interesting.
Exception when calling the Decompress method with data from the
{System.Reflection.TargetInvocationException: Exception has been
thrown by the target of an invocation. --->
System.Runtime.InteropServices.COMException (0x8000FFFF): Catastrophic
failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
at
Microsoft.BizTalk.Message.Interop.CompressionStreams.DecompressSequentialStream(Stream
rawStream, Stream& compressedStream, UInt32& bytesRead, UInt32&
bytesWritten)
at
Microsoft.BizTalk.Message.Interop.CompressionStreams.Decompress(Stream
stm, UInt32& bytesRead, UInt32& bytesWritten)
at
Microsoft.BizTalk.Message.Interop.CompressionStreams.Decompress(Stream
stm)
--- End of inner exception stack trace ---
Link to post on how to get the XML from the message body:http://groups.google.se/group/microsoft.public.biztalk.general/browse...
Code for invoking the
Microsoft.BizTalk.Message.Interop.CompressionStreams.Decompress using
Assembly pipelineAssembly = Assembly.LoadFrom(string.Concat(<path to
Type compressionStreamsType =
pipelineAssembly.GetType("Microsoft.BizTalk.Message.Interop.CompressionStreams",
true);
return (Stream)compressionStreamsType.InvokeMember("Decompress",
BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Static,
null, null, new object[] { (object)stream });
I've finally found a solution this (at least in BizTalk 2006). I've
written a short post on it here.

http://www.webhostingsearch.com/blogs/richard/reading-the-message-body-and-context-from-the-biztalkdtadb-using-operations-library-in-biztalk-2006/

RIchard Hallgren
Lex Hegt
2011-06-07 13:00:01 UTC
Permalink
Hi Richard,

Based on an article from Thiago Almeida I wrote a tool that decompresses Message content and context, see the following link:
http://biztalkia.blogspot.com/2010/12/c-solution-to-decompress-biztalk.html

Thiago's article: http://connectedthoughts.wordpress.com/2008/04/02/3-ways-of-programatically-extracting-a-message-body-from-the-biztalk-tracking-database/

It's on CodePlex as well:
http://btsdecompress.codeplex.com

The tool enables the user to fire sql queries at the MessageBox-database or the Tracking-database. When you select fields which contain message content or context, you can decompress those fields by surrounding them with functions I designed.

I hope you want to try this tool. Feel free to contact me through my blog.

Regards,
Lex
Post by r***@gmail.com
Hi,
The question on how to get hold of the XML data from tracking database
(we're then talking about both the XML body and the XML context) gets
asked over and over again without being answered ... A while a ago
Niriven answered on how to decompress the actual message body from the
BizTalkDTADb (see link at the end of this message). As the XML is
compressed the clue is to use a
Microsoft.BizTalk.Message.Interop.CompressionStreams.Decompress method
from the Microsoft.BizTalk.Pipeline.dll - I've tried it and it works
like charm. The only thing to think of is that the CompressionStreams
class is internal in BizTalk 2006 (not in 2004 I think) and that one
has to invoke the Decompress method using reflection (I've added the
code for that at the end of this message).
However the decompression does not work on the context of that message
(stored in the imgContext field)! One only gets an exception from the
DecompressSequentialStream method that is called from the Decompress
method (I've pasted the exception for everyone to read). This means
that it's still impossible to get hold of values like the
InterchangeID or ReceiveLocation for the message that lives in the
context of a message but are not directly in own fields within the
BizTalkDTADb.
It is possible to get the XML data using the
MSBTS_TrackedMessageInstance WMI script but this is slow as the script
only support saving messages to file!
So, basically we can decompress and read the message body stored in
the imgPart field (thanks to Niriven and the Reflector tool) but how
on earth are the data in the imgContext field stored! I've tried
reading it like plain the using the encodings I could think of without
success ... Has anyone tried this before and succeed or failed? Any
information is interesting.
Exception when calling the Decompress method with data from the
{System.Reflection.TargetInvocationException: Exception has been
thrown by the target of an invocation. --->
System.Runtime.InteropServices.COMException (0x8000FFFF): Catastrophic
failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
at
Microsoft.BizTalk.Message.Interop.CompressionStreams.DecompressSequentialStream(Stream
rawStream, Stream& compressedStream, UInt32& bytesRead, UInt32&
bytesWritten)
at
Microsoft.BizTalk.Message.Interop.CompressionStreams.Decompress(Stream
stm, UInt32& bytesRead, UInt32& bytesWritten)
at
Microsoft.BizTalk.Message.Interop.CompressionStreams.Decompress(Stream
stm)
--- End of inner exception stack trace ---
http://groups.google.se/group/microsoft.public.biztalk.general/browse_thread/thread/599c038807317802/30473829b681de6d?lnk=st&q=imgpart&rnum=3&hl=sv#30473829b681de6d
Code for invoking the
Microsoft.BizTalk.Message.Interop.CompressionStreams.Decompress using
Assembly pipelineAssembly = Assembly.LoadFrom(string.Concat(<path to
Type compressionStreamsType =
pipelineAssembly.GetType("Microsoft.BizTalk.Message.Interop.CompressionStreams",
true);
return (Stream)compressionStreamsType.InvokeMember("Decompress",
BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Static,
null, null, new object[] { (object)stream });
Post by r***@gmail.com
I've finally found a solution this (at least in BizTalk 2006). I've
written a short post on it here.
http://www.webhostingsearch.com/blogs/richard/reading-the-message-body-and-context-from-the-biztalkdtadb-using-operations-library-in-biztalk-2006/
RIchard Hallgren
Loading...