【问题标题】:WCF - Getting CommunicationExceptionWCF - 获取通信异常
【发布时间】:2013-09-04 18:47:05
【问题描述】:

我有一个 WCF 服务,它为不同的 WCF 服务提供身份验证/授权。

这是一个示例方法:

 public int AddCustomerStopInfo(CustomerStop stop)
            {
                var request = new AddCustomerStopInfoRequest(stop);

                var service = new ChannelFactory<IAccountManagementChannel>("WSHttpBinding_IAccountManagement").CreateChannel();

                try
                {
                    var response = service.AddCustomerStopInfo(request);
                    service.Close();

                    return response.AddCustomerStopInfoResult;
                }
                catch (CommunicationException e)
                {
                    service.Abort();
                    throw;
                }

            }

在 service.AddCustomerStopInfo() 方法调用中,抛出异常。消息内容如下:

无法打开安全通道,因为与 远程端点失败。这可能是由于缺席或不正确 EndpointAddress 中指定的 EndpointIdentity 用于创建 渠道。请验证指定或暗示的 EndpointIdentity EndpointAddress 正确识别远程端点。

服务的服务器绑定如下:

 <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IAccountManagement" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
          maxBufferPoolSize="524288" maxReceivedMessageSize="100065536"
          messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
          allowCookies="false">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00"
            enabled="false" />
          <security mode="None" />
        </binding>

...

 <services>
      <service behaviorConfiguration="ABCD.Service.Service1Behavior"
        name="ABCD.Service.AccountManagement">
        <endpoint address="" behaviorConfiguration="ValidationBehavior"
          binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IAccountManagement"
          name="WSHttpBinding_IAccountManagement" contract="ABCD.Service.IAccountManagement">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" behaviorConfiguration="" binding="mexHttpBinding"
          contract="IMetadataExchange" />
      </service>

和客户端:

<client>
  <endpoint address="[site location]/AccountManagement.svc"
    binding="wsHttpBinding" 
    contract="IAccountManagement" name="WSHttpBinding_IAccountManagement">
  </endpoint>
</client>

两个服务都在同一台服务器上。如果其他服务有&lt;security mode="None"&gt;,我不明白为什么我会收到此错误?

【问题讨论】:

  • 您有服务器的安全证书吗?是自签吗?您是否指定了https 地址?您输入的用户名和密码是否正确?
  • 是的,有一个证书,是的,它是自签名的。 (这是在测试环境中。)我没有指定 https。让我试试这些然后回复你 - 我不认为这是一个问题。
  • 你有一个wsHttpBinding,所以你应该使用https,尽管它不是强制性的。如果您在测试环境中,您可能必须添加代码以允许与测试服务器建立许可连接。
  • 设置 Https 并添加许可连接解决了这个问题。如果您将其写为答案,我会为您标记。感谢您的帮助。

标签: wcf wcf-binding


【解决方案1】:

当您尝试通过 wsHttpBinding 使用安全绑定时,您需要通过 https 连接到服务器并使用调试代码来允许连接到您的测试服务器。

这是因为您只有一个自签名证书,而 https 在安全证书方面非常严格。

【讨论】:

    猜你喜欢
    • 2011-10-17
    • 1970-01-01
    • 2011-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    相关资源
    最近更新 更多