Here’s a little snippet of code I use to get the size of an XLANG message in bytes. Very efficient and always correct, it loops through each message part and adds up each part’s Size property. This is useful for when you need to know the size of the message inside an orchestration.
//Returns the sum of the size of the message parts
public static int GetMessageSize(Microsoft.XLANGs.BaseTypes.XLANGMessage msg)
{
int msgSize = 0;
try
{
foreach (Microsoft.XLANGs.BaseTypes.XLANGPart xp in msg)
{
msgSize += Convert.ToInt32(xp.GetPartProperty(typeof(Microsoft.XLANGs.BaseTypes.Size)));
}
}
catch (Exception ex)
{
System.Diagnostics.EventLog.WriteEntry("XMLUtils GetMessageSize",
ex.Message, System.Diagnostics.EventLogEntryType.Error);
}
return msgSize;
}
Sorry but that doesn’t work for me. When I use this piece of code with an XML message, I obtain the size of -1.
It might depend on the adapter that’s received the message, but it worked for me quite a few times.