self signed cert. The underlying connection was closed: Could not establish trust relationship

前端 未结 2 1779
醉梦人生
醉梦人生 2020-12-17 19:25

Trying to set up a self signed certificate, for our intranet\'s web services site. The certificate itself shows it is \"ok\" but when trying to invoke a method from the web

相关标签:
2条回答
  • 2020-12-17 19:35

    Add this line of code somewhere before you create your service client.

    ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);
    

    Do note: this will cause your app to accept all invalid certs and just keep moving. If this is not acceptable, you can attach a function to that and do processing to determine if the cert error is ok or not

    0 讨论(0)
  • 2020-12-17 19:44

    iamkrillin did have a working solution, in that his code will ignore the invalid cert, and allow the application to use the web service.

    In addition to this, I have corrected the certificate so that i no longer need to ignore the invalid cert.

    The host header value (shown in OP) was WebServices.mycompany.vmc , but the "Common Name" or "Friendly Name" for the certificate (shown in OP screenshot 3 for 'Certification Path') was WebServices.

    The common name, and the website URL need to match. I recreated the self-signed cert with a common name of "WebServices.mycompany.vmc" and now the certificate error is gone. The web service is available for use, without the coder needing to ignore invalid certs for the application.

    0 讨论(0)
提交回复
热议问题