MSMQ and the Message.Body property

K

Kimmo Laine

Hi,

how can i be sure that the MSMQ Message.Body property contains something
valid? If i send the message like this:

public void SendMyMessage( int msgCode, object msgData ) {
Message msg = new Message();
msg.AppSpecific = msgCode;
msg.Body = msgData;

m_MyQueue.Send( msg );
}

Sometimes the msgData is valid object (array of objects actually) and
sometimes its just null. When its null and i try to check it

if( msg.Body != null ) {
// . . .
}

I get XmlException - "The root element is missing"! If i but empty string
into Body-field when i don´t have data: XmlException again, with the same
message.

The Message.BodyType seems to be allways 0. MessageQueue formatter is set
like this:

myQueue.Formatter = new XmlMessageFormatter( new Type[] { typeof(
object[] ) } );


I could do it like this

object[] data;
try {
data = ( object[] )msg.Body;
} catch ( Exception exc ) {
data = null;
}

but i don´t like this... Is there a better way? Am i missing something?


thx

Kimmo Laine
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top