I've got a very simple console app that is having trouble peeking at a message in a remote private queue.
var queues = MessageQueue.GetPrivateQueuesByMachine(machineName);
var queue = queues.Where(x=>x.FormatName == queueName).Single();
Message message = queue.Peek();
The Peek call fails with a MessageQueueException of "Access to Message Queuing system is denied".
Using the same client machine and user I am able to view the queue using Queue Explorer and with the Message Queuing Snap In.
Experimenting with a local queue I am only able to reproduce the error by taking away the Peek permission on the queue but that also stops it in the other tools.
I've seen lots of information that points me to the issues outlined here.
However, it seems like if any of those things was the issue, I wouldn't be able to do it using the other tools as well.
EDIT I have been able to get this to work using the MSMQQueueInfo/MSMQQueue COM objects without changing any credentials. It would be nice if I could make it work using the .NET libraries but at least I have a workaround.
My issue was that when GetPrivateQueuesByMachine
is used to get the queue, it uses a access mode of SendAndReceive
which is asking for more permissions then I had. I had to use the MessageQueue constructor to specify the AccessMode. (In this case Peek.)
In the end, I was able to get this to work using code similar to the following:
var queue = new MessageQueue(@"FormatName:DIRECT=OS:machineName\private$\queueName", QueueAccessMode.Peek);
Message message = queue.Peek();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With