Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot programmatically peek into a remote (private) msmq: Access to Message Queuing system is denied

Tags:

c#

msmq

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.

like image 870
drs9222 Avatar asked Aug 28 '15 15:08

drs9222


1 Answers

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();
like image 83
drs9222 Avatar answered Sep 30 '22 04:09

drs9222