0

我想从本地网络上的另一台计算机接收消息,所以我MessageQueue以这种方式创建:

private static string QueueName = ".\\Private$\\Q1";
    public void SendMessage()
    {           
        if (!MessageQueue.Exists(QueueName))
            MessageQueue.Create(QueueName);

        //
    }

    public void ReceiveMessage()
    {
        // Connect to the a queue on the local computer.
        MessageQueue myQueue = new MessageQueue(QueueName);

        // Set the formatter to indicate body contains an Order.
        myQueue.Formatter = new XmlMessageFormatter(new Type[] { typeof(Queue.Order) });

        try
        {
            // Receive and format the message. 
            Message myMessage = myQueue.Receive();
            ///
    }

我还尝试MessageQueue使用以下格式创建我的@"MachineName\QueueName"但收到 MessageQueueException。

4

1 回答 1

0

If you go to "Computer Management" and look under "Services and Applications" > "Message Queueing" > "Private Queues" do you see your queue named "Q1"? If so, are there any messages in it? You may need to adjust the properties on the queue (right click > Properties > Security). If you're in a development environment you can start by giving Everyone Full Control. Once you have it working, try to figure out the minimum set of permissions. You may also want to create the queue from the computer management mmc, rather than in the code.

于 2013-09-24T15:07:33.280 回答