MSMQ Formatter and XmlMessageFormatter

Discussion in 'Microsoft C# .NET' started by Chizl, Feb 28, 2008.

  1. Chizl

    Chizl Guest

    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
    ....
    }

    --
    /*Chizl*/
     
    Chizl, Feb 28, 2008
    #1
    1. Advertisements

  2. Chizl

    Chizl Guest

    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?

    --
    /*Chizl*/
    "Chizl" <> wrote in message
    news:%23Q$...
    > 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
    > ....
    > }
    >
    > --
    > /*Chizl*/
    >
     
    Chizl, Feb 28, 2008
    #2
    1. Advertisements

  3. Chizl

    Mufaka Guest

    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.

    Chizl wrote:
    > 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?
    >
     
    Mufaka, Feb 28, 2008
    #3
  4. Chizl

    Dan Kelley Guest

    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.

    "Mufaka" wrote:

    > 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.
    >
    > Chizl wrote:
    > > 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?
    > >

    >
     
    Dan Kelley, Feb 29, 2008
    #4
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrick De Ridder

    Formatter

    Patrick De Ridder, Aug 1, 2003, in forum: Microsoft C# .NET
    Replies:
    2
    Views:
    213
    Jay B. Harlow [MVP - Outlook]
    Aug 1, 2003
  2. Andreas Huber

    How to subclass System.Runtime.Serialization.Formatter?

    Andreas Huber, Oct 28, 2003, in forum: Microsoft C# .NET
    Replies:
    4
    Views:
    316
    Andreas Huber
    Oct 29, 2003
  3. Eric Workman

    Implementing IFormatter for Custom Formatter

    Eric Workman, Jan 7, 2004, in forum: Microsoft C# .NET
    Replies:
    1
    Views:
    846
    Nicholas Paldino [.NET/C# MVP]
    Jan 7, 2004
  4. Bhavesh Shah

    MSMQ binding Stop processing after Cluster MSMQ failover

    Bhavesh Shah, Apr 24, 2009, in forum: Microsoft C# .NET
    Replies:
    0
    Views:
    822
    Bhavesh Shah
    Apr 24, 2009
  5. Gomez
    Replies:
    0
    Views:
    257
    Gomez
    Apr 18, 2010
Loading...

Share This Page