为什么我无法从远程公共事务队列接收消息?

发布于 2024-08-02 22:16:25 字数 2103 浏览 7 评论 0原文

我在 Windows Server 2008 上使用 C#,并且希望从同一域中另一台计算机上的公共事务队列接收消息。错误如下所示:

System.Messaging.MessageQueueException: Cannot import the transaction.
   at System.Messaging.MessageQueue.ReceiveCurrent(TimeSpan timeout, Int32 action, CursorHandle cursor, MessagePropertyFilter filter, MessageQueueTransaction internalTransaction, MessageQueueTransactionType transactionType)
   at System.Messaging.MessageQueue.Receive(TimeSpan timeout, MessageQueueTransactionType transactionType)
   at JobManagerLib.JobProcessor.Process(Action waitForNewMessageCallback) in C:\Dev\OtherProjects\POC\WindowsService\JobManagerSample\JobManagerLib\JobProcessor.cs:line 132

我尝试过 DTCPing,它在一个方向上成功,但在另一个方向上失败。这是日志的相关部分:

++++++++++++hosts      ++++++++++++
127.0.0.1       localhost
::1             localhost

08-20, 15:47:22.739-->Error(0x424) at clutil.cpp @256
08-20, 15:47:22.739-->-->OpenCluster
08-20, 15:47:22.739-->-->1060(The specified service does not exist as an installed service.)
++++++++++++++++++++++++++++++++++++++++++++++
     DTCping 1.9 Report for DEV-MSMQ2  
++++++++++++++++++++++++++++++++++++++++++++++
RPC server is ready
++++++++++++Validating Remote Computer Name++++++++++++
08-20, 15:47:26.207-->Start DTC connection test
Name Resolution:
    dev-msmq1-->192.168.22.11-->Dev-msmq1
08-20, 15:47:26.222-->Start RPC test (DEV-MSMQ2-->dev-msmq1)
RPC test failed

有人知道为什么这可能会失败吗? Windows 防火墙已针对 MSDTC 开放。很难找到有关 Windows 2008 和 MSMQ 的大量信息。

编辑:队列名称为 FormatName:DIRECT=OS:dev-msmq1\getmap 和 FormatName:DIRECT=OS:dev-msmq1\logevent。它们是公共的事务队列,每个人都拥有对它们的查看/接收权限。我的代码的相关部分如下:

using (TransactionScope tx = new TransactionScope(TransactionScopeOption.RequiresNew))
{
    using (var queue = new MessageQueue(QueueName))
    {
        queue.Formatter = new XmlMessageFormatter(new string[] { _targetParameterType });
        var message = queue.Receive(TimeOut, MessageQueueTransactionType.Automatic);
        string messageId = message.Label;

...
    }
}

谢谢

I'm using C# on Windows Server 2008, and I want to receive a message from a public transactional queue on another machine in the same domain. The error looks like this:

System.Messaging.MessageQueueException: Cannot import the transaction.
   at System.Messaging.MessageQueue.ReceiveCurrent(TimeSpan timeout, Int32 action, CursorHandle cursor, MessagePropertyFilter filter, MessageQueueTransaction internalTransaction, MessageQueueTransactionType transactionType)
   at System.Messaging.MessageQueue.Receive(TimeSpan timeout, MessageQueueTransactionType transactionType)
   at JobManagerLib.JobProcessor.Process(Action waitForNewMessageCallback) in C:\Dev\OtherProjects\POC\WindowsService\JobManagerSample\JobManagerLib\JobProcessor.cs:line 132

I've tried DTCPing, which succeeds in one direction but fails in the other. Here is the pertinent part of the log:

++++++++++++hosts      ++++++++++++
127.0.0.1       localhost
::1             localhost

08-20, 15:47:22.739-->Error(0x424) at clutil.cpp @256
08-20, 15:47:22.739-->-->OpenCluster
08-20, 15:47:22.739-->-->1060(The specified service does not exist as an installed service.)
++++++++++++++++++++++++++++++++++++++++++++++
     DTCping 1.9 Report for DEV-MSMQ2  
++++++++++++++++++++++++++++++++++++++++++++++
RPC server is ready
++++++++++++Validating Remote Computer Name++++++++++++
08-20, 15:47:26.207-->Start DTC connection test
Name Resolution:
    dev-msmq1-->192.168.22.11-->Dev-msmq1
08-20, 15:47:26.222-->Start RPC test (DEV-MSMQ2-->dev-msmq1)
RPC test failed

Does anybody have any idea why this might be failing? The Windows Firewall has been opened for MSDTC. It's hard to find much info about Windows 2008 and MSMQ.

EDIT: The queue names are FormatName:DIRECT=OS:dev-msmq1\getmap, and FormatName:DIRECT=OS:dev-msmq1\logevent. They are public, transactional queues, and Everyone has peek/receive permission on them. The pertinent part of my code is as follows:

using (TransactionScope tx = new TransactionScope(TransactionScopeOption.RequiresNew))
{
    using (var queue = new MessageQueue(QueueName))
    {
        queue.Formatter = new XmlMessageFormatter(new string[] { _targetParameterType });
        var message = queue.Receive(TimeOut, MessageQueueTransactionType.Automatic);
        string messageId = message.Label;

...
    }
}

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

娇纵 2024-08-09 22:16:25

所以我确实找到了一个解决方案:完全放弃整个事情并改用 WCF 和 net.Msmq 绑定。现在队列通信工作正常。

So I did find a solution: abandon the whole thing altogether and switch to using WCF and the net.Msmq binding. Now the queue communication is working fine.

葮薆情 2024-08-09 22:16:25

确保两台机器的时钟同步。我之前见过这种情况,身份验证将失败,因为服务器和客户端关闭了一分钟。即使队列是公共的并且对每个人都有权限,这种情况也会发生。

Make sure, both machine's clocks are in sync. I seen this before where authentication will fail because the server and the client are off time by a minute. This will happen even if the queues are public and have permissions on everyone.

源来凯始玺欢你 2024-08-09 22:16:25

为了完整起见,运行 IPv4 时仅允许 MSDTC 和 MSMQ 通过防火墙是不够的:

您还需要让 ICMP 流量通过防火墙(无论防火墙如何,IPv6 都可以解析主机名,但您的 DTCPIng 日志表明您正在运行 IPv4 )。

我一直在努力解决您在 DTCPing 中看到的相同错误,就我而言,它是由防火墙阻止 ICMP 流量触发的。

Just for completeness, allowing only MSDTC and MSMQ through the firewall is not enough when running IPv4:

You need to let ICMP traffic through the firewall as well (IPv6 can resolve host names regardless of the firewall, but your DTCPIng log indicates you are running IPv4).

I have struggled with the same error you see in DTCPing, and in my case it turned out to be triggered by the firewall blocking the ICMP traffic.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文