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?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. Patrick De Ridder

    Formatter

    Patrick De Ridder, Aug 1, 2003, in forum: Microsoft C# .NET
    Replies:
    2
    Views:
    347
    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:
    522
    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:
    1,162
    Nicholas Paldino [.NET/C# MVP]
    Jan 7, 2004
  4. Mike Deakins

    Unable to deserialize a class using SOAP formatter

    Mike Deakins, Mar 20, 2004, in forum: Microsoft C# .NET
    Replies:
    0
    Views:
    358
    Mike Deakins
    Mar 20, 2004
  5. Simon

    A code formatter

    Simon, May 29, 2004, in forum: Microsoft C# .NET
    Replies:
    11
    Views:
    474
    Martin Maat
    May 31, 2004
  6. Guest

    Custom formatter creation

    Guest, Jan 21, 2005, in forum: Microsoft C# .NET
    Replies:
    2
    Views:
    494
    Guest
    Jan 21, 2005
  7. Bhavesh Shah

    MSMQ binding Stop processing after Cluster MSMQ failover

    Bhavesh Shah, Apr 24, 2009, in forum: Microsoft C# .NET
    Replies:
    0
    Views:
    1,041
    Bhavesh Shah
    Apr 24, 2009
  8. Gomez
    Replies:
    0
    Views:
    327
    Gomez
    Apr 18, 2010
Loading...