Я пытаюсь понять, как это работает, и меня совершенно смущают различия между именем пути и именем формата при доступе к очередям MSMQ.
Я обнаружил некоторые похожие проблемы в следующих сообщениях:
- Вызовы MSMQ через HTTP не достигают очереди назначения
- Как настроить сервер MSMQ так, чтобы к нему можно было получить доступ через Интернет.
- Как использовать MSMQ через http через соответствующую привязку WCF?
Я хочу добиться следующего:
Клиент: отправляет данные в очередь через http.
Сервер: получает данные из очереди через http.
Я хочу, чтобы сервер, клиент и очередь размещались на потенциально разных компьютерах. (Пока я тестирую все на одной машине).
Здесь у меня есть следующий код, который демонстрирует то, что я имею в виду:
Сначала я создаю очередь:
Код: Выделить всё
if(!System.Messaging.MessageQueue.Exists(@".\Private$\SimplestExamplePrivateQueue");
System.Messaging.MessageQueue.Create(@".\Private$\SimplestExamplePrivateQueue");
Затем на стороне клиента у меня есть функция обратного вызова, которая вызывается, когда пользователь нажимает кнопку для отправки сообщения.
Код: Выделить всё
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) ;
}
Код сервера:
Затем у меня есть кнопка, которая вызывает функцию обратного вызова для синхронного чтения одного сообщения из очереди на стороне сервера:
Код: Выделить всё
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);
}
}
Код: Выделить всё
The specified format name does not support the requested operation. For example, a direct queue format name cannot be deleted.
Код: Выделить всё
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
Подробнее здесь: https://stackoverflow.com/questions/194 ... -the-queue
Мобильная версия