Using MSMQ over HTTP. How to address the queue?
Asked Answered
C

1

8

I'm currently trying to use MSMQ with C# and .NET in order to achieve IPC. I am trying to understand how it works, and I'm quite confused about the differences between Path name and Format name when accessing MSMQ queues. I've found some similar issues in the following posts:

  1. MSMQ calls over HTTP not reaching destination queue
  2. How to setup MSMQ server so that it can be accessed over the Internet
  3. How to use MSMQ over http through the respective WCF binding?

However, they're all using MSMQ and WCF, and I don't want to use WCF for now.

What I want to achieve is the following:

Client: Sends data to the queue through http.

Server: Receives data from the queue through http.

My point here is that I want that either server, client and the queue to be hosted in potentially different computers. (For now I'm testing everything in the same machine).

Here I have the following code, which demonstrates what I have in mind:

First, I create the queue:

if(!System.Messaging.MessageQueue.Exists(@".\Private$\SimplestExamplePrivateQueue");
    System.Messaging.MessageQueue.Create(@".\Private$\SimplestExamplePrivateQueue");

Client code:

Then, at the client side, I have a callback function which is invoked when the user presses a button in order to send a message.

private void button1_Click(object sender, System.EventArgs e)
{
    try
    {           
        // Create a connection to the queue
        System.Messaging.MessageQueue mq = new System.Messaging.MessageQueue(@"FormatName:Direct=http://localhost/msmq/Private$/SimplestExamplePrivateQueue");

        // Create a point object to send
        Point myPoint = new Point (Convert.ToInt32(textBox2.Text), Convert.ToInt32(textBox3.Text)) ;

        // Send object 
        mq.Send (myPoint) ;
    }

    // Catch the exception that signals all types of error
    // from the message queueing subsystem. Report error
        // to the user. 
    catch (System.Messaging.MessageQueueException mqx)
    {
        MessageBox.Show (mqx.Message) ;
    }

Everything until here works fine.

Server code:

Then, I have a button which invokes a callback function to synchronously read one message from the queue at the server side:

private void button1_Click(object sender, EventArgs e)
{
    try
    {
        // Create a connection to the queue
        var mq = new MessageQueue(@"Direct=http://localhost/msmq/Private$/SimplestExamplePrivateQueue");

        // Set the queue's formatter to decode Point objects
        mq.Formatter = new XmlMessageFormatter(new[] {typeof (Point)});

        // Receive message synchronously
        Message msg = mq.Receive();

        // Convert received message to object that we think was sent
        var pt = (Point) msg.Body;

        // Display it to the user
        MessageBox.Show(pt.ToString(), "Received Point");
    }

    // Report any exceptions to the user. A timeout would cause such
    // an exception
    catch (Exception x)
    {
        MessageBox.Show(x.Message);
    }
}

In my (limited) understanding of MSMQ, this should work. However, when I call Message msg = mq.Receive(); I get the following exception:

The specified format name does not support the requested operation. For example, a direct queue format name cannot be deleted.

And the Stack Trace:

at System.Messaging.MessageQueue.MQCacheableInfo.get_ReadHandle()
   at System.Messaging.MessageQueue.StaleSafeReceiveMessage(UInt32 timeout, Int32 action, MQPROPS properties, NativeOverlapped* overlapped, ReceiveCallback receiveCallback, CursorHandle cursorHandle, IntPtr transaction)
   at System.Messaging.MessageQueue.ReceiveCurrent(TimeSpan timeout, Int32 action, CursorHandle cursor, MessagePropertyFilter filter, MessageQueueTransaction internalTransaction, MessageQueueTransactionType transactionType)
   at System.Messaging.MessageQueue.Receive()
   at InternetQueueingRecipient.Form1.button1_Click(Object sender, EventArgs e) in c:\Users\felipedalcin\Documents\MSMQ\MSMQandNET\InternetQueuing\InternetQueueingRecipient\Form1.cs:line 85

Does anyone have an idea of how I could debug this or even if what I want to do is achievable by those means?

Collective answered 16/10, 2013 at 21:15 Comment(1)
You cannot receive messages over HTTPPeltry
P
0

Direct format names that specify the HTTP or HTTPS protocol cannot be used to peek at or receive messages, only to send them

Prophet answered 12/8, 2021 at 6:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.