I have an object which I would like to store in XML format in an MSMQ queue. What I expect it to appear in the queue body is this:
<?xml version="1.0"?>
<Object>
<Text>Hello World!</Text>
<Number>5</Number>
</Object>
However, when I store the object, I would see a diferent result in the body:
3C 3F 78 6D 6C 20 76 65 <?xml ve
72 73 69 6F 6E 3D 22 31 rsion="1
2E 30 22 3F 3E 0D 0A 3C .0"?>..<
4F 62 6A 65 63 74 3E 0D Object>.
0A 09 3C 54 65 78 74 3E .<Text>H
48 65 6C 6C 6F 20 57 6F ello Wor
72 6C 64 21 3C 2F 54 65 ld!</tex
78 74 3E 0D 0A 09 3C 4E t>..<Num
75 6D 62 65 72 3E 35 3C ber>5</N
2F 4E 75 6D 62 65 72 3E umber>..
0D 0A 3C 2F 4F 62 6A 65 </Object
63 74 3E >
I'm not sure what the actual format used here is, so I can't workout how I would alter it. I have tried adding messageQueue.Formatter = new BinaryMessageFormatter();
and messageQueue.Formatter = new XmlMessageFormatter();
to the MessageQueue object, but I get exactly the same result.
My code for sending the object is:
// This part of the code of creating the TestObject isn't what I'm using in development,
// this is just for showing you that I'm using an object.
TestObject item = new TestObject();
item.Text = "Hello World!";
item.Number = 5;
MessageQueue messageQueue;
Message message;
messageQueue = new MessageQueue(@".\Private$\myqueue");
message = new Message(item);
messageQueue.Send(message);
How would I alter my code to make sure it sends and stores in an XML format?
Any help would be appreciated.