【问题标题】:WCF SSL configuration error perhapsWCF SSL 配置错误可能
【发布时间】:2010-08-30 14:50:51
【问题描述】:

试图通过 SSL 让 HelloWorld 工作。阅读所有这些文档:

  1. X509FindType

  2. How to: Use wsHttpBinding with Windows Authentication and Transport Security in WCF Calling from Windows Forms

  3. How to: Configure a Port with an SSL Certificate

  4. How to: Create Temporary Certificates for Use During Development

  5. Windows Communication Foundation (WCF) Screencasts

我所知道的是证书似乎是正确创建和部署的(实际上是两个证书)。不过,我想我的 web.config 有问题(抱歉,此时不能更具体)。就好像没有服务器监听 443 或者客户端需要一个 http 而不是 https。有人可以给我指出适当的资源和/或告诉我我做错了什么吗?

web.config 在这里:

<?xml version="1.0" encoding="utf-8" ?>

<configuration>
  <appSettings>
    <add key="HTTPBaseAddress" value=""/>
  </appSettings>
  <system.serviceModel>
    <services>
      <service behaviorConfiguration="MyServiceTypeBehaviors" name="MyWCFServices.HelloWorldService">
        <clear />
        <endpoint address="mex" binding="mexHttpBinding" name="mexEndpoint" contract="IMetadataExchange" listenUriMode="Explicit">
          <identity>
            <dns value="localhost" />
            <certificateReference storeName="My" storeLocation="LocalMachine" x509FindType="FindBySubjectDistinguishedName" />
          </identity>
        </endpoint>
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="" name="SSLendpoint" contract="MyWCFServices.IHelloWorldService">
          <identity>
            <dns value="localhost" />
            <certificateReference x509FindType="FindByThumbprint" findValue="‎82a39faaeb18bf9585b334ca83264add3d5b26ee" />
          </identity>
        </endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyServiceTypeBehaviors" >
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

客户端 app.config 在这里:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="NoSecurity">
                    <security mode="None" />
                </binding>
                <binding name="SSLsecurity">
                    <security mode="Transport">
                        <transport clientCredentialType="None" />
                        <message clientCredentialType="Certificate" /
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://localhost:443/HelloWorldSSL/HelloWorldService.svc"
                binding="wsHttpBinding" bindingConfiguration="" contract="IHelloWorldService"
                name="wsHttpBinding_IHelloWorldService" />
        </client>
    </system.serviceModel>
</configuration>

如果需要任何其他信息/屏幕截图 - 我会很乐意提供(像往常一样)。希望这是一个可以回答的问题:)

【问题讨论】:

    标签: c# .net wcf configuration ssl


    【解决方案1】:

    您的配置不正确。您没有在端点中定义自定义绑定配置,因此不使用 HTTPS。将这个用于服务器:

    <bindings>
      <wsHttpBinding>
        <binding name="SSLSecurity">
          <security mode="Transport">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <behaviors> 
      <serviceBehaviors> 
        <behavior name="MyServiceTypeBehaviors" > 
          <serviceMetadata httpGetEnabled="true" /> 
        </behavior> 
      </serviceBehaviors> 
    </behaviors> 
    <services> 
      <service behaviorConfiguration="MyServiceTypeBehaviors" 
        name="MyWCFServices.HelloWorldService"> 
        <endpoint address="mex" binding="mexHttpBinding" name="mexEndpoint" 
           contract="IMetadataExchange" listenUriMode="Explicit" /> 
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="SSLSecurity" 
           name="SSLendpoint" contract="MyWCFServices.IHelloWorldService" /> 
      </service> 
    </services> 
    

    供客户使用:

    <bindings>   
      <wsHttpBinding>     
        <binding name="SSLSecurity">   
          <security mode="Transport">   
            <transport clientCredentialType="None" />   
          </security>   
        </binding>   
      </wsHttpBinding>   
    </bindings>   
    <client>   
      <endpoint address="https://localhost:443/HelloWorldSSL/HelloWorldService.svc"    
         binding="wsHttpBinding" bindingConfiguration="SSLSecurity"   
         contract="IHelloWorldService" name="wsHttpBinding_IHelloWorldService" />   
    </client> 
    

    【讨论】:

    • 谢谢 - 这解决了一些问题(有一些自定义)。但是,现在收到另一个错误:根据验证程序,远程证书无效。但是,在下一个我的stackoverflow问题中:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-18
    • 1970-01-01
    • 1970-01-01
    • 2018-02-01
    • 2020-04-24
    • 2013-06-15
    相关资源
    最近更新 更多