I need to communicate with a legacy application from my C# app via the Windows Message Queue.
The legacy application expects plain string messages in a particular private queue, but I can’t seem to stop the System.Messaging.MessageQueue from wrapping my message in XML!
The code I’m testing is very simple:
MessageQueue myQueue = new MessageQueue(@".\Private$\tolegacy");
Message msg = new Message("My Test String");
myQueue.Send(msg);
The trouble is that the message is being XML serialized and appears in the queue as:
<?xml version="1.0"?><string>My Test String</string>
I can’t modify the behaviour of the legacy application, so I need to stop the System.Messaging.MessageQueue from formatting my message as XML.
Can anyone help?
You can create your own formatter (it is a class that implements IMessageFormatter and assign it to the Formatter property of the Message
Here is a link to MSDN to the Message.Formatter property.
I have not tried this but you should be able to write your message using the BodyStream, I believe this will bypass the formatter.