I've been searching for a while now on a way to retrieve message body and context from BizTalk without having to use WMI,
simply because I didn't want to write my messages to file, read them back in, parse the context and then delete the generated
Interesting blog post I stumbled upon was this: View post
But this was not sufficient, because no one managed to get the FULL message context from this method. However, there is a very easy way to do this.
First of all, I defined two strings representing a property name, and a property namespace. They will be the out values for our method.
Now the Context object we get from the tracked message out of the BizTalk Operations dll, implements the Microsoft.BizTalk.Message.Interop.IBaseMessageContext interface. When you look closely at it's methods, you will see a "ReadAt" method. That's the one we need to use.
The Context object also contains a CountProperties variable, which doesn't need any further explanation I think.
So the next part is pretty straight-forward right?
Loop through the CountProperties values, use them as indexes, and call the ReadAt(index, name, namespace) method
for every loop passage, and hold the property value in another string variable.
string sname = "";
string snamespace = "";
for (int i = 0; i < imsg.Context.CountProperties; i++)
string value = imsg.Context.ReadAt(i, out sname, out snamespace).ToString();
Console.WriteLine(sname + " (" + snamespace + ") = " + value);
And there you have it! Full message context!
Enjoy experimenting with this very cool way of getting body and context of a BizTalk message! IMHO, this is a much better
approach than the WMI way.