I send a handful of identical (except for Id#, obviously) messages to an MSMQ queue on my local machine. The body of the messages is a serialized XElement object.
When I try to process the first message in the queue, I am able to successfully de-serialize the Message.Body object and save it to file. However, when trying to process the next (or any subsequent) message, the Message.Body is absent, and an exception is thrown. I have verified the Message ID's are correct for the message attempting to be processed.
The XML being serialized is properly formed.
Any ideas? I am basing my code on the Microsoft MSMQ Book order sample found here: http://msdn.microsoft.com/en-us/library/ms180970%28VS.80%29.aspx
// Create Envelope XML object
XElement envelope = new XElement(env + "Envelope", new XAttribute(XNamespace.Xmlns + "env", env.NamespaceName) <snip>
//Send envelope as message body
MessageQueue myQueue = new MessageQueue(String.Format(@"FORMATNAME:DIRECT=OS:localhost\private$\mqsample"));
myQueue.DefaultPropertiesToSend.Recoverable = true;
// Prepare message
Message myMessage = new Message();
myMessage.ResponseQueue = new MessageQueue(String.Format(System.Globalization.CultureInfo.InvariantCulture,
@"FORMATNAME:DIRECT=TCP:192.168.1.217\private$\mqdemoAck"));
myMessage.Body = envelope;
// Send the message into the queue.
myQueue.Send(myMessage,"message label");
//Retrieve messages from queue
System.Messaging.Message message = mqOrderQueue.Receive();
The Message.Body value I see on the 1st retrieve is as expected: <?xml version="1.0" encoding="utf-8"?>
<string>Some String</string>
However, the 2nd and subsequent retrieve operations Message.Body is: "Cannot deserialize the message passed as an argument. Cannot recognize the serialization format."
How does this work fine the first time but not after that? I have tried message.Dispose() after retrieving it but it did not help.
Thank you very much for any help on this!