简体   繁体   English

无法以编程方式查看远程(私有)msmq:拒绝访问消息队列系统

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

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". Peek调用失败,MessageQueueException为“拒绝访问消息队列系统”。

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. 尝试使用本地队列我只能通过取消队列中的Peek权限来重现错误,但也会在其他工具中停止它。

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. 编辑我已经能够使用MSMQQueueInfo / MSMQQueue COM对象使其工作,而无需更改任何凭据。 It would be nice if I could make it work using the .NET libraries but at least I have a workaround. 如果我可以使用.NET库使其工作,那将是很好的,但至少我有一个解决方法。

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. 我的问题是,当使用GetPrivateQueuesByMachine获取队列时,它使用SendAndReceive的访问模式,这要求获得更多权限。 I had to use the MessageQueue constructor to specify the AccessMode. 我不得不使用MessageQueue构造函数来指定AccessMode。 (In this case Peek.) (在这种情况下是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();

I too had the same problem. 我也有同样的问题。 In my case, I was initializing Message Queue in parent thread and accessing Peek function in child thread. 在我的例子中,我在父线程中初始化Message Queue并在子线程中访问Peek函数。

In case you are using multi threading, try to keep initialization and access of function in same thread. 如果您使用多线程,请尝试在同一线程中保持函数的初始化和访问。

That the queue shows up in various utilities just doesn't tell you that much. 队列显示在各种实用程序中只是不会告诉你那么多。 Such a utility is pretty unlikely to be peeking at messages. 这样的实用程序不太可能偷看消息。 In general, the default access permissions allows everybody to see the queue and post messages to it. 通常,默认访问权限允许每个人查看队列并向其发布消息。 But not retrieve them. 但是没有检索它们。

On the machine that owns this queue, use Control Panel > Administrative Tools > Computer Management > Services and Applications > Message Queuing > Private Queues. 在拥有此队列的计算机上,使用“控制面板”>“管理工具”>“计算机管理”>“服务和应用程序”>“消息队列”>“专用队列”。 Select the queue and right click > Properties > Security tab. 选择队列并右键单击>属性>安全选项卡。 Note how Everbody has some rights, like "Get Properties" and "Send Message". 请注意Everbody如何拥有某些权限,例如“获取属性”和“发送消息”。 But not "Peek Message". 但不是“偷看消息”。

Sane thing to do is just add the user account that you use on the other machine and tick the rights you need to get the job done. 简单的事情就是添加您在另一台计算机上使用的用户帐户,并勾选完成工作所需的权限。 If this machine is managed by an admin then you'll need to ask them to do it for you. 如果此计算机由管理员管理,那么您需要让他们为您执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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