0

试图让简单的 Hello World(通过 SSL)工作,但收到以下错误:根据验证过程,远程证书无效。

服务器 App.config 是:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior name="mexBehavior">
                    <serviceMetadata httpGetEnabled="true" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <bindings>
            <wsHttpBinding>
                <binding name="SSLSecurity">
                    <security mode="Transport">
                        <transport clientCredentialType="None" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <services>
            <service behaviorConfiguration="mexBehavior" name="HelloServiceLibrary.HelloService">
                <clear />
                <endpoint address="ws" binding="wsHttpBinding" name="wsEndpoint"
                    contract="HelloServiceLibrary.IHelloService">
                    <identity>
                        <dns value="localhost" />
                    </identity>
                </endpoint>

                <endpoint address="https://localhost:443/hellossl" binding="wsHttpBinding" name="wssslEndpoint"
                    bindingConfiguration="SSLSecurity" contract="HelloServiceLibrary.IHelloService">
                  <identity>
                    <certificateReference x509FindType="FindByThumbprint" findValue="‎82a39faaeb18bf9585b334ca83264add3d5b26ee" />
                    <dns value="localhost" />
                  </identity>
                </endpoint>

                <endpoint address="mex" binding="mexHttpBinding" name="mexEndpoint"
                    contract="IMetadataExchange">
                    <identity>
                        <dns value="localhost" />
                    </identity>
                </endpoint>
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:8989/hello" />
                    </baseAddresses>
                </host>
            </service>
        </services>
    </system.serviceModel>
</configuration>

请指教我做错了什么。

更新:证书已成功部署在本地计算机上的受信任的根证书颁发机构中。

4

3 回答 3

1

将此添加到您的 WCF 配置中并让我知道输出。

 <system.diagnostics>
    <trace autoflush="true" />
        <sources>
            <source name="System.Net" maxdatasize="1024">
                <listeners>
                    <add name="MyTraceFile"/>
                </listeners>
            </source>
          <source name="System.Net.Sockets" maxdatasize="1024">
                <listeners>
                    <add name="MyTraceFile"/>
                </listeners>
            </source>  
       </sources>

        <sharedListeners>
            <add
              name="MyTraceFile"
              type="System.Diagnostics.TextWriterTraceListener"
              initializeData="System.Net.trace.log"
            />
        </sharedListeners>
        <switches>
            <add name="System.Net" value="Verbose" />
          <add name="System.Net.Sockets" value="Verbose" /> 
        </switches>
</system.diagnostics>

这是在黑暗中刺伤。

检查以确保您已将其安装给所有用户。

打开 MMC
添加管理单元(证书)
-检查计算机帐户(下一步)
-选择您的计算机
完成

现在将证书重新安装到“受信任的根证书颁发机构”,它将被所有用户信任。

于 2010-08-31T13:02:38.363 回答
0

不确定这是否对您有帮助,但我回顾了我是如何将 app.config 设置为几周前我使用证书编写的简单安全服务的。为了正确配置服务的配置,您可能需要考虑以下几点:

<bindings>
    <wsHttpBinding>
        ...
        <security>
            <transport clientCredentialType="Certificate"  />
        </security>
    </wsHttpBinding>
</bindings>

现在在我的配置中,我定义了一个端点行为,它提供元数据来告诉服务客户端将使用什么来获取证书:

    <behaviors>
        <endpointBehaviors>
            <behavior name="ClientBehavior">
                        <clientCredentials>
                            <clientCertificate findValue="WcfClient" storeLocation="LocalMachine" storeName="My"
                 x509FindType="FindBySubjectName"/>
                            <serviceCertificate>
                                <authentication certificateValidationMode="PeerTrust" />
                            </serviceCertificate>
                        </clientCredentials>
                    </behavior>
        </endpointBehaviors>
    </behaviors>
于 2010-08-31T13:47:02.797 回答
0

如果您只需要一个安全链接,即仅加密,无需客户端身份验证,那么您无需设置任何客户端凭据。这就是您应该做的所有事情:
1. 将 IIS 配置为使用 SSL
2. 在您的服务上配置 HTTPS 端点
3. 将客户端配置为使用上述端点

而已。如果您的证书无效,您可能必须按照此处所述进行自定义证书验证:MSDN

祝你好运!

于 2011-04-20T07:34:38.253 回答