12

我开发了一个 WCF 服务,它作为 Windows 服务托管并公开一个 MSMQ 端点。

我在 SERVER1 上有客户端应用程序,在 SERVER2 上有 MSMQ 和 WCF 服务。

当 SERVER1/ClientApp 尝试将消息推送到 SERVER2 MSMQ 时,我收到以下错误:

    System.TypeInitializationException: The type initializer for 'System.ServiceModel.Channels.Msmq' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'mqrt.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
       at System.ServiceModel.Channels.UnsafeNativeMethods.MQGetPrivateComputerInformation(String computerName, IntPtr properties)
       at System.ServiceModel.Channels.MsmqQueue.GetMsmqInformation(Version& version, Boolean& activeDirectoryEnabled)
       at System.ServiceModel.Channels.Msmq..cctor()
       --- End of inner exception stack trace ---
       at System.ServiceModel.Channels.Msmq.EnterXPSendLock(Boolean& lockHeld, ProtectionLevel protectionLevel)
       at System.ServiceModel.Channels.MsmqOutputChannel.OnSend(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.OutputChannel.Send(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [7]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at FacilityManager.Service.NotificationsProcessorServiceReference.INotificationsProcessor.SendNewReactiveTaskNotifications(NewReactiveTaskDataContract newReactiveTaskDataContract)

SERVER1 和 SERVER2 都运行 Windows Server 2008 R2 Enterprise (6.1 SP1),并且都通过服务器管理器中的添加功能安装了 MSMQ。

我知道缺少 DLL(从错误中非常明显!),但我不知道我应该安装什么才能将 dll 放在它应该在的位置。

在 Windows 资源管理器中的搜索显示 DLL 存在于两台服务器上的以下目录中......

  • C:\Windows\System32
  • C:\Windows\SysWOW64
  • C:\Windows\winsxs\x86_microsoft-windows-msmq-runtime-core_31bf3856ad364e35_6.1.7601.17514_none_5768e2ad17453bd6
  • C:\Windows\winsxs\amd64_microsoft-windows-msmq-runtime-core_31bf3856ad364e35_6.1.7601.17514_none_b3877e30cfa2ad0c

任何帮助表示赞赏。

4

3 回答 3

24

一个明显的旁白;如果您没有安装Windows 功能 -> Microsoft 消息队列 (MSMQ) 服务器,那么您将收到此错误。只需转到程序和功能,然后打开或关闭 Windows 功能

于 2014-11-02T22:28:35.577 回答
5

我并不聪明,但现在一切正常。

在 SO 和 Google 上几个小时后,我最终只是通过编写一个快速控制台应用程序来检查两个服务器上是否安装了 MSMQ,其中的代码是从这里抓取的......

https://stackoverflow.com/a/16104212/192999

我在 Server1 和 Server2 上都运行了控制台应用程序,结果都返回 True to IsMsmqInstalled。

然后我运行了我的应用程序,并且不再出现“无法加载 DLL 'mqrt.dll'”错误。

我不知道调用是否NativeMethods.LoadLibrary("Mqrt.dll");注册了 DLL 或其他什么,但它确实解决了我的问题。

我希望这对将来的人有所帮助!

于 2013-09-03T13:56:45.007 回答
1

这可能是由于 SERVER2 上的服务在 MSMQ 完成自身初始化之前启动并完成其初始化造成的。对此进行测试的最简单方法是重新启动托管 WCF MSMQ 终结点的服务。如果 WCF 服务托管在 IIS 中,则弹跳应用程序池可能会做同样的事情,但我不确定——我从未处理过 IIS 托管的 MSMQ 端点。

如果重新启动服务可以解决您的问题并且您自己的服务是 Windows 服务,那么您可以将 MSMQ 作为依赖项添加到您自己的服务中,这样它就会延迟启动,直到 MSMQ 准备好。 这个关于服务器故障的答案描述了如何做到这一点。顺便说一句,您要依赖的服务称为“消息队列”

于 2014-10-10T14:16:59.717 回答