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?
First, go to Services and Applications > Message Queuing. 2. Right-click on the queue you want to clear, and then select All Tasks > Purge. Note: If you are unsure about deleting the messages, or you have data hoarding issues, you can export the list first.
But, even if a text message doesn’t include any instructions for making it stop, there’s a practically universal way to unsubscribe. To unsubscribe from automated text messages sent to your mobile phone number, just respond to the text with one of the following words: “Stop” and “Unsubscribe” are the most common commands.
myMessageQueue.Send ("Text 1."); myMessageQueue.Close (); myMessageQueue.Send ("Text 2."); //Resources are re-acquired. When you call Close, all MessageQueue properties that directly access the Message Queuing queue are cleared out. The Path, DefaultPropertiesToSend, Formatter, and MessageReadPropertyFilter all remain as they were.
To do so, call the MessageQueue (String, Boolean) or MessageQueue (String, Boolean, Boolean) constructor, and set the sharedModeDenyReceive parameter to true. Create the MessageQueue with connection caching disabled.
Using the ActiveXMessageFormatter will give you the desired result. We had the same issue with just wanting to pass a string to a queue and have the listener process read in the body as a string. The ActiveXMessageFormatter is used for serializing/deserializing primitive data types and will not put an XML wrapper on your input as is the case with the default XmlMessageFormatter.
mq.Formatter = new ActiveXMessageFormatter();
Here is another link describing the 3 different formatters as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With