如何在发送MSMQ消息时解决名称转换失败

时间:2016-08-29 23:48:04

标签: wcf msmq wcf-binding netmsmqbinding

我最近关注如何使用MSMQ建立三方排队系统Egor,其中发布者,队列服务器和订阅者都在Active Directory域中的不同系统上。我已经成功完成了第1部分和第2部分的前半部分。但是,当我继续使用第2部分的后半部分并启用传输安全性时,我收到以下错误:at System.ServiceModel.Channels.MsmqFormatName.FromQueuePath(String queuePath) at System.ServiceModel.Channels.MsmqUri.ActiveDirectory.UriToFormatName(Uri uri) at System.ServiceModel.Channels.MsmqOutputChannel.OpenQueue() --- End of inner exception stack trace --- Server stack trace: at System.ServiceModel.Channels.MsmqOutputChannel.OpenQueue() at System.ServiceModel.Channels.MsmqOutputChannel.OnOpenCore(TimeSpan timeout) at System.ServiceModel.Channels.MsmqOutputChannel.OnBeginOpen(TimeSpan timeout, AsyncCallback callback, Object state) at System.ServiceModel.Channels.CommunicationObject.OpenAsyncResult.InvokeOpen() at System.ServiceModel.Channels.CommunicationObject.OpenAsyncResult..ctor(CommunicationObject communicationObject, TimeSpan timeout, AsyncCallback callback, Object state) at System.ServiceModel.Channels.CommunicationObject.BeginOpen(TimeSpan timeout, AsyncCallback callback, Object state) at System.ServiceModel.Channels.ServiceChannel.OnBeginOpen(TimeSpan timeout, AsyncCallback callback, Object state) at System.ServiceModel.Channels.CommunicationObject.OpenAsyncResult.InvokeOpen() at System.ServiceModel.Channels.CommunicationObject.OpenAsyncResult..ctor(CommunicationObject communicationObject, TimeSpan timeout, AsyncCallback callback, Object state) at System.ServiceModel.Channels.CommunicationObject.BeginOpen(TimeSpan timeout, AsyncCallback callback, Object state) at System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.BeginCall(ServiceChannel channel, TimeSpan timeout, AsyncCallback callback, Object state) at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.BeginCallOnce(TimeSpan timeout, CallOnceManager cascade, AsyncCallback callback, Object state) at System.ServiceModel.Channels.ServiceChannel.BeginEnsureOpened(TimeSpan timeout, AsyncCallback callback, Object state) at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.StartEnsureOpen(Boolean completedSynchronously) at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.FinishEnsureInteractiveInit(IAsyncResult result, Boolean completedSynchronously) at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.StartEnsureInteractiveInit() at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.Begin() at System.ServiceModel.Channels.ServiceChannel.BeginCall(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, TimeSpan timeout, AsyncCallback callback, Object asyncState) at System.ServiceModel.Channels.ServiceChannel.BeginCall(ServiceChannel channel, ProxyOperationRuntime operation, Object[] ins, AsyncCallback callback, Object asyncState) at System.Threading.Tasks.TaskFactory`1.FromAsyncImpl[TArg1,TArg2,TArg3](Func`6 beginMethod, Func`2 endFunction, Action`1 endAction, TArg1 arg1, TArg2 arg2, TArg3 arg3, Object state, TaskCreationOptions creationOptions) at System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.CreateTask(ServiceChannel channel, ProxyOperationRuntime operation, Object[] inputParameters) at System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.CreateTask(ServiceChannel channel, IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)

我已经验证了以下内容:

  1. 根据this article,在三方系统中的所有计算机上启用了MSMQ的Active Directory集成。
  2. 队列的URL与启用安全性之前的URL完全相同,这很好,没有任何解析错误。
  3. 我在安装MSMQ this StackOverflow post时遵循Windows提供的说明。
  4. 我得到的堆栈跟踪的相关部分是:

    Me.TestContext.WriteLine("Executing under user '{0}'", WindowsIdentity.GetCurrent().Name)
    
    Dim msg = New System.Messaging.Message()
    
    msg.Body = "This is a test message"
    msg.Label = "Test Message"
    msg.Formatter = new ActiveXMessageFormatter()
    
    Dim queue = new MessageQueue("FormatName:DIRECT=OS:mymsmqservermachine.mydomain.network.ads\private$\Path/To/MyQueuedService.svc")
    
    queue.Send(msg)
    

    根据堆栈跟踪的内容,似乎失败来自解析Active Directory中的队列名称。我尝试过以下方法来尝试解决这样的问题:

    1. 简化名称以不包含句点或斜杠(不起作用)
    2. 使用公共队列而不是专用队列,如果MSDN上的原始教程中省略了此步骤(它没有,则无效)
    3. 在这一点上,我没有想法。在使用WCF和net.msmq绑定之前是否有人遇到此错误并解决了他们的问题?

      编辑:当从同一台机器和同一个用户运行以下测试代码时,我可以完全正确地向队列发送消息:

      {{1}}

1 个答案:

答案 0 :(得分:0)

通过纯粹的侥幸,我偶然发现了解决方案,我a special repository

解决方案的要点是我必须在我的客户端为我的WCF端点绑定添加DNS身份:

if (html.Contains("widgetName")) isPlatformName = true;

我为Visual Basic代码向世界道歉,它是一个遗留应用程序,并不是我的选择。