在IIS上使用MSMQ协议配置WCF服务 - 无效的URI:无法解析主机名

时间:2013-02-14 11:30:29

标签: wcf iis msmq wcf-binding

我正在尝试使用配置的端点在IIS(IIS7,Windows 7)上设置WCF服务,而且正如IIS配置一样,它是一个受到伤害的世界。该服务在VS2010上的调试器下运行良好,但是当我开始部署它时,我在打开http://localhost:9000/MyApplication/_vti_bin/ListData.svc时收到以下消息:

[UriFormatException: Invalid URI: The hostname could not be parsed.]
  System.Runtime.AsyncResult.End(IAsyncResult result) +650220
  System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +210733
  System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +166

有趣的是,如果我刷新它,消息就会改变:

[ArgumentException: An item with the same key has already been added.]
   System.Runtime.AsyncResult.End(IAsyncResult result) +650220
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +210733
   System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +166

我认为第二个错误是第一个错误的结果,所以我试图先跟踪它。

现在,我知道你在想什么:“在这个时刻看到一个冗长乏味的Web.Config文件真的很棒。”你的愿望是我的命令:

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="loggingenabled" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true"/>
  </system.web>
  <system.serviceModel>
    <services>
      <service behaviorConfiguration="SecurityBehavior" name="MSMQSecuredService.SecuredMSMQService">
        <endpoint address="net.msmq://MyMachine/private/securedqueue"
          binding="netMsmqBinding" bindingConfiguration="SecuredBinding"
          name="EndpointMSMQ" contract="MSMQSecuredService.ISecuredMSMQService">
          <identity>
            <dns value="MyMachine" />
          </identity>
        </endpoint>
<!-- I have tried configuring the endpoint address to everything from the full path to this "/" with no change in outcome -->
        <endpoint address="/" binding="basicHttpBinding" name="EndPointHTTP"
          contract="MSMQSecuredService.ISecuredMSMQService" />
        <endpoint address="mex" binding="mexHttpBinding" name="EndPointIMEX"
          contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://MyMachine:9000/MyApplication" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="SecurityBehavior">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="True"/>
          <serviceCredentials>
            <serviceCertificate findValue="CertServer" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName"/>
            <clientCertificate>
              <certificate findValue="CertClient" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName"/>
              <authentication certificateValidationMode="None"/>
            </clientCertificate>
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <netMsmqBinding>

        <binding name="SecuredBinding" exactlyOnce="false" receiveErrorHandling="Fault">
          <security mode="Message">
            <message clientCredentialType="Certificate"/>
          </security>
        </binding>
      </netMsmqBinding>

    </bindings>
  </system.serviceModel>

  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>

显然,我已经努力模糊确切的机器,应用程序和端口名称,所以如果存在轻微的不匹配,那可能不是问题。

在IIS上我已经在网站上配置了绑定以包含net.msmq - 我对该问题的最佳猜测是“绑定信息”不正确 - 如果我将其设置为当前机器的机器名称我得到上述内容消息,如果我将其设置为“localhost”,它会给我一个ASP.Net服务器错误,并在事件日志和WCF跟踪文件中出现以下内容:

The service '/MyApplication/_vti_bin/ListData.svc' does not exist. ---> System.ServiceModel.EndpointNotFoundException: The service '/MyApplication/_vti_bin/ListData.svc' does not exist.

我猜测它抱怨的URI可能是绑定信息中的主机名,但是我找不到任何关于它需要的信息,或者如果localhost是正确的,那么如何深入研究问题。

编辑添加:启用WCF跟踪后,我看到发生以下模式:

<Description>MsmqActivation service started scan for queues.</Description>
<AppDomain>/LM/W3SVC/2/ROOT/MyApplication-1-130053972428149879</AppDomain>

然后

<Description>Throwing an exception.</Description><AppDomain>/LM/W3SVC/2/ROOT/My-Application-1-130053972428149879</AppDomain>
<Exception>
  <ExceptionType>System.ServiceModel.EndpointNotFoundException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>The service '/MyApplication/_vti_bin/ListData.svc' does not exist.</Message><StackTrace>   at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity)
   at System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(String relativeVirtualPath, EventTraceActivity eventTraceActivity)
   at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest()
   at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest()
   at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequest(Object state)
   at System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
   at System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
   at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
</StackTrace><ExceptionString>System.ServiceModel.EndpointNotFoundException: The service '/MyApplication/_vti_bin/ListData.svc' does not exist.</ExceptionString>
</Exception>

最后我们看到了这个:

<Description>MsmqActivation service cannot discover queues.</Description>
<AppDomain>/LM/W3SVC/2/ROOT/MyApplication-1-130053250352242318</AppDomain>
<ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord">
  <Host>.</Host>
  <PublicQueues>True</PublicQueues>
</ExtendedData>
<Exception>
  <ExceptionType>System.Messaging.MessageQueueException, System.Messaging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</ExceptionType>
  <Message>A workgroup installation computer does not support the operation.</Message>
  <StackTrace>
  at System.Messaging.MessageQueue.GetMachineId(String machineName)
  at System.Messaging.MessageQueueCriteria.set_MachineName(String value)
  at System.Messaging.MessageQueue.GetPublicQueuesByMachine(String machineName)
  at System.ServiceModel.Channels.MsmqBindingMonitor.OnTimer(Object state)
  </StackTrace>
  <ExceptionString>System.Messaging.MessageQueueException (0x80004005): A workgroup installation computer does not support the operation.
     at System.Messaging.MessageQueue.GetMachineId(String machineName)
     at System.Messaging.MessageQueueCriteria.set_MachineName(String value)
     at System.Messaging.MessageQueue.GetPublicQueuesByMachine(String machineName)
     at System.ServiceModel.Channels.MsmqBindingMonitor.OnTimer(Object state)
  </ExceptionString>
</Exception>

现在这个最终异常看起来可能是最具指示性的 - 当我尝试写入的队列为./private$/MyApplication时,系统似乎正在寻找 public 队列 - 所以我需要改变什么来指向正确的方向?

2 个答案:

答案 0 :(得分:2)

我遇到了同样的问题并在此处找到了解决方案 - http://vijayvepak.blogspot.ru/2012/09/an-item-with-same-key-has-already-been.html 解: 转到IIS,转到webapp的网站。 右键单击 - &gt;编辑绑定 确保net.msmq协议的绑定信息设置为localhost

它帮助了我们所有工作站,我们遇到了这个错误。

答案 1 :(得分:0)

IIS只支持Http协议。如果您需要使用MSMQ,您必须选择其他选项,如WAS或自托管(赢取表单,WPF或Win服务)。 在下表中,您可以找到每个WCF托管选项支持的功能。

enter image description here