简体   繁体   中英

Can my machine read messages from another local machine if my MessageQueue is private?

I want to receive messages from another computer on the local network so I created MessageQueue in this way:

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();
            ///
    }

I also tried to create my MessageQueue with the format of @"MachineName\\QueueName" but received a MessageQueueException.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM