My blog has moved!

Visit http://blog.adamroderick.com/ and update your bookmarks.

Monday, April 27, 2009

Convert XLANGMessage to string

This method has come in handy so much more than I ever thought it would. It's sole purpose is to take a BizTalk message and convert it to a string. One example of where I use it is when I am logging information from within an orchestration.

I suppose you could add an index parameter if you wanted to use this with multi-part messages.



public static class Utilities {
/// <summary>
/// Converts the contents of a message to a string. Careful with large messages,
/// as it will try to put the entire message into the string variable.
/// Not intended for multi-part messages, unless the body part is the first part
/// </summary>
/// <param name="msg">The BizTalk XLANGMessage</param>
public static string ConvertMsgToString(XLANGMessage msg)
{
lock (xmlDoc)
{
xmlDoc = (XmlDocument)msg[0].RetrieveAs(typeof(XmlDocument));
return xmlDoc.DocumentElement.OuterXml;
}
}
}


This usage is from an Expression shape in the Orchestration designer:



System.Diagnostics.EventLog.WriteEntry(
"Entry Title"
, Utilities.ConvertMsgToString(
<MessageVariableHere>
)
);

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home