更改证书后的WCF SOAP安全协商

时间:2018-12-12 19:41:31

标签: c# wcf ssl certificate wshttpbinding

将自签名证书“​​ localhost”(DNS = localhost)更改为“ Cloudflare Origin Certificate”(dns = mydomain.com)后,出现以下错误:

SOAP security negotiation with 'http://localhost:8000/MyService.svc' for target 'http://localhost:8000/MyService.svc' failed. See inner exception for more details.

内部异常:

Either the client credential was invalid or there was an error collecting the client credentials by the SSPI.

我注意到的是,在启动客户端之后,我会看到输入凭据的窗口。邓诺为什么。

我的所作所为

  1. IIS中生成的证书请求
  2. CloudFlare上的完整证书
  3. 使用CloudFlare根CA将接收到的密钥粘贴到文本文件中
  4. IIS中的完整证书(个人,LocalMachine)
  5. 在MMC中添加到受信任的发布者CloudFlare根CA(LocalMachine)
  6. 对于WCF网站,将SSL证书更改为CloudFlare
  7. 客户端值从“ localhost”更改为“ mydomain.com”
  8. 服务器值从“ localhost”更改为“ mydomain.com”
  9. 更改了
  10. 的findValue

WCF web.config

<system.serviceModel>
    <client />
    <behaviors>
      <serviceBehaviors>
        <behavior name="authBehavior">
          <serviceAuthorization principalPermissionMode="UseWindowsGroups">
            <authorizationPolicies>
              <add policyType="WCF.Common.AuthorizationPolicy, WCF" />
            </authorizationPolicies>
          </serviceAuthorization>
          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="WCF.Common.IdentityValidator, WCF" />
            <serviceCertificate findValue="CloudFlare Origin Certificate" storeLocation="LocalMachine" x509FindType="FindBySubjectName" storeName="My" />
          </serviceCredentials>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
        <behavior name="svcBehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <basicHttpsBinding>
        <binding name="basicHttpsEndpointBinding" maxReceivedMessageSize="1073741824" maxBufferSize="1073741824" maxBufferPoolSize="1073741824">
          <readerQuotas maxDepth="32" maxArrayLength="1073741824" maxStringContentLength="1073741824" />
          <security mode="Transport">
            <transport clientCredentialType="Windows" />
          </security>
        </binding>
      </basicHttpsBinding>
      <wsHttpBinding>
        <binding name="wsHttpEndpointBinding"></binding>
      </wsHttpBinding>
    </bindings>
    <services>
      <service name="WCF.MyService" behaviorConfiguration="svcBehavior">
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpEndpointBinding" contract="WCF.IMyService">
          <identity>
            <dns value="mydomain.com" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

客户端app.config

<system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="MessageAndUserName">
                    <security mode="Message">
                        <message clientCredentialType="UserName" />
                    </security>
                </binding>
                <binding name="WSHttpBinding_IMyService" />
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:8777/MyService.svc"
                binding="wsHttpBinding" contract="WCF.IMyService"
                name="WSHttpBinding_IMyService">
                <identity>
                    <dns value="mydomain.com" />
                </identity>
            </endpoint>
        </client>

      <behaviors>  
        <serviceBehaviors>  
          <behavior name="DefaultServiceBehavior">  
            <serviceMetadata httpGetEnabled="true" />  
            <serviceDebug includeExceptionDetailInFaults="true" />  
          </behavior>  
        </serviceBehaviors>  
      </behaviors>  
    </system.serviceModel>

我在WCF中托管其他服务,也在客户端中托管了一些服务,但不需要。

我在WCF和客户端之间使用wsHttpBindings。我该怎么办才能消除此错误?

使用wsHttpBinding等的目的是什么...:仅允许此客户端与MyService通信。不允许其他任何人。客户端应用将在域中的多台计算机上运行。您是否建议使用其他方法?

感谢任何想法!

编辑:错误计算机不在域中运行。都不适用于域:/

中的计算机

EDIT2:安全模式传输 WCF web.config绑定:

<wsHttpBinding>
        <binding name="wsHttpEndpointBinding">
          <security mode="Transport">
            <message clientCredentialType="None" />
          </security>
        </binding>
      </wsHttpBinding>

客户端配置绑定:

<bindings>
            <wsHttpBinding>
              <binding name="WSHttpBinding_IMyService">
                <security mode="Transport">
                  <message clientCredentialType="None" />
                </security>
              </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://localhost:8001/MyService.svc"
                binding="wsHttpBinding" contract="WCF.IMyService"
                name="WSHttpBinding_IMyService">
                <identity>
                    <dns value="mydomain.com" />
                </identity>
            </endpoint>
        </client>

IIS: Certificate

1 个答案:

答案 0 :(得分:1)

这里有一些资源需要审查,以帮助确定NetTcpBinding是否适合您,这听起来像是因为您在内部使用Web服务。

NetTcpBinding 当WCF服务及其客户端位于Intranet基础结构中时,netTcpBinding最佳。由于它仅支持TCP协议而不支持HTTP,因此无法通过Internet访问服务。

此安全绑定用于在Intranet计算机中与二进制编码的SOAP消息一起发送。它支持可靠性,交易和安全性。如果您在IIS中使用netTcpBinding和主机WCF服务,则需要在系统上进行一些设置,而IIS this article将为您提供必需的设置。

一些疑难解答相关问题的提示:

  • 双击MMC中的证书是否会给您任何错误消息 在“证书信息”标题下?
  • 您能够在浏览器中从客户端浏览服务吗?
  • 是IIS中分配的证书
  • 绑定是否正确
  • 客户端使用与服务主机相同的绑定吗?
  • 您的端点是否引用了正确的绑定和服务行为

有关NetTcpBinding的其他有用信息:

https://stackoverflow.com/a/3375161/2016162