C# 基于SSL的Web服务&x2B;X.509返回SSL/TLS错误

C# 基于SSL的Web服务&x2B;X.509返回SSL/TLS错误,c#,asp.net,web-services,wcf,ssl,C#,Asp.net,Web Services,Wcf,Ssl,我在Visual Studio 2013中编写了一个asmx web服务。 WS正在使用HTTPS和X.509连接到提供商进行身份验证 CertificateMappingAuthenticationModule NOTIFY_MODULE_START RequestNotifications AUTHENTICATE_REQUEST AUTH_START Authentication MapCliCert AUTH_END Authentication CertificateMappingAu

我在Visual Studio 2013中编写了一个asmx web服务。 WS正在使用HTTPS和X.509连接到提供商进行身份验证

CertificateMappingAuthenticationModule NOTIFY_MODULE_START RequestNotifications AUTHENTICATE_REQUEST
AUTH_START Authentication MapCliCert
AUTH_END Authentication
CertificateMappingAuthenticationModule NOTIFY_MODULE_END RequestNotifications AUTHENTICATE_REQUEST NOTIFICATION_CONTINUE  
AnonymousAuthenticationModule NOTIFY_MODULE_START RequestNotifications  AUTHENTICATE_REQUEST
我曾尝试使用“basicHttpBinding”和“basicHttpsBinding”(Web.config)进行连接,但总是出现以下错误

错误:System.ServiceModel.Security.SecurityNegotiationException:无法为具有权限“www.providers-site.se”的SSL/TLS建立安全通道。-->System.Net.WebException:请求被中止:无法创建SSL/TLS安全通道。在System.Net.HttpWebRequest.GetResponse()中,位于

我已经为X.509创建了一个行为,并为端点创建了一个绑定,请参见下文。 我做错了什么? 改用wsHttpBinding对我有好处吗

<behaviors>
   <endpointBehaviors>
     <behavior name="CertBehaviour">
       <clientCredentials>
         <clientCertificate findValue="MyCertCN" storeLocation="LocalMachine"
                            storeName="My" x509FindType="FindBySubjectName" />
          <serviceCertificate>
          <authentication certificateValidationMode="PeerTrust" />
          </serviceCertificate>
       </clientCredentials>
     </behavior>
   </endpointBehaviors>
 </behaviors>

...

<basicHttpsBinding>
   <binding name="mySoapBinding">
     <security mode="Transport">
       <transport clientCredentialType="Certificate" />
        <message clientCredentialType="Certificate" />
     </security>
   </binding>
  </basicHttpsBinding>

...

<client>
  <endpoint address="https://www.providers-site.se/na/na_epersondata/services/personpostXML"
                behaviorConfiguration="CertBehaviour" binding="basicHttpsBinding"
                bindingConfiguration="mySoapBinding" contract="webservice.NaPersonPostXMLWS"
                name="personpostXML" />
</client>

确保您的asmx计算机的受信任根存储中有提供者站点服务的证书链。您可以通过在浏览器中键入ur lin来查找:

并查看其证书链。浏览器也会显示警告

暂时解决证书错误的另一个选项是尝试以下操作:

ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => 
    {
     // put a breakpoint here
     var tempSslErrors = sslPolicyErrors;
     return  true;
    }

如果您查看
SSLPolicyError,它可能会给出一些指示。

嗨,迈克!对不起,我对IIS7不太适应。如何执行跟踪?我查看了下面的链接,但我的屏幕看起来与“禁用ASP:”部分中的屏幕截图完全不同。我确实做了跟踪,但看不出哪里出错了。我应该寻找什么?我可以从asmx机器转到而不显示任何证书错误。我已将根证书和中间证书导入计算机信任库。我也尝试了“ServicePointManager.ServerCertificateValidationCallback”,但仍然得到相同的错误。如何检查“sslPolicyErrors”?