MSMQ Formatter and XmlMessageFormatter

C

Chizl

On the MQReceiveCompleted method below, I get an error "Name cannot begin
with the '.' character, hexadecimal value 0x00. Line 1, position 40."..
This data is XML that I'm putting into this queue.
---------
<?xml version=""1.0""
encoding=""utf-8""?><DATA><FIELD1>CHIZL</FIELD1><FIELD2>DA
MAN</FIELD2></DATA>
---------

Methods
---------------------
public void SetupMSMQ()
{
String szMQPath = @".\private$\TestQueue";

if (!MessageQueue.Exists(szMQPath))
MessageQueue.Create(szMQPath);

//setup MQ Request Path
MessageQueue mq = new MessageQueue(szMQPath);
//format of message will be XML

mq.Formatter = new XmlMessageFormatter(new Type[] { typeof(String) });
//vs..
//((XmlMessageFormatter)mq.Formatter).TargetTypeNames = new string[] {
"Data" };

//setup async call
mq.ReceiveCompleted += new
ReceiveCompletedEventHandler(MQReceiveCompleted);
//callback ready
mq.BeginReceive();

...
...
}


private static void MQReceiveCompleted(Object source,
ReceiveCompletedEventArgs asyncResult)
{
//connect to the queue.
MessageQueue mq = (MessageQueue)source;
//end the asynchronous Receive operation.
System.Messaging.Message m = mq.EndReceive(asyncResult.AsyncResult);
//display message information on the screen.
String szXML = (String)m.Body; //Fails
....
}
 
C

Chizl

I think I know the problem, when I write it to the queue, I'm using VBS and
I noticed in the queue the data is in Unicode. So how do I get it to write
as ASCII?
 
M

Mufaka

I vaguely recall having to use a BinaryFormatter when reading queue
items inserted by another language. You can try that and just get the
message body as a string.
 
D

Dan Kelley

For what it is worth I believe you mean the ActiveXFormatter, which should be
used when receiving messages sent by non .Net applications, for exmaple VB6
applications.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top