Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop my System.Messaging.MessageQueue from wrapping my strings in XML?

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?

like image 534
Damovisa Avatar asked Jun 02 '09 00:06

Damovisa


People also ask

How do I clear the message queue?

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.

Is there a way to stop an automated text message?

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.

What happens when I Close a messagequeue?

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.

How do I disable connection caching in a messagequeue?

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.


1 Answers

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.

like image 52
jaywon Avatar answered Sep 19 '22 12:09

jaywon