MSMQ empty object on message body

Posted by Owen on Stack Overflow See other posts from Stack Overflow or by Owen
Published on 2010-03-21T18:34:33Z Indexed on 2010/03/21 18:41 UTC
Read the original article Hit count: 210

Filed under:
|

Ok, so I'm very VERY new to MSMQ and I'm already confused.

I have created a private queue and added a few messages to it, all good so far. BUT when I retrieve the messages back from the queue the message body contains a empty object of the type I added. By this I don't mean that the body is null, it does have a reference to a type of the object that I added, but it's not instantiated so all the properties are in their null or default state.

This is the code I use to add to the queue:

using (var mQueue = new MessageQueue(QueueName))
{
    var msg = new Message(observation)
    {
            Priority = MessagePriority.Normal,
             UseJournalQueue = true,
            AcknowledgeType = AcknowledgeTypes.FullReceive,
    };
    mQueue.Send(msg);
}

And this is the code that dequeues the messages:

using (var mQueue = new MessageQueue(QueueName))
{
    mQueue.MessageReadPropertyFilter.SetAll();
    ((XmlMessageFormatter)mQueue.Formatter).TargetTypes =
                                                  new[] { typeof(Observation) };
    var msg = mQueue.Receive(new TimeSpan(0, 0, 5));
    var observation = (Observation)msg.Body;

    return observation;
}

© Stack Overflow or respective owner

Related posts about msmq

Related posts about c#