Self signed certificate. The main connection was closed: failed to establish trust

Trying to configure a self-signed certificate for our intranet website. The certificate itself shows that it is "good", but when you try to call a method from a web service, it gives an error, and when you add a web link, it gives a warning.

Here are the steps and some screenshots so that I can provide accurate information.

Windows 2003 server. IIS. Website - "WebServices.companyName.vmc"

one

Here is the site header for the site

2

From the server, it shows that the certificate is "ok".

enter image description here

Here are some site settings

enter image description here


Now in visual studio 2008 by adding a web link

enter image description here

Clicking Yes on the popup

enter image description here

Pressing "No" for this popup several times in a row.

enter image description here

After running a line of code that calls a web service ... I get this error

The connected connection was closed: Failed to establish a relationship trust for the secure SSL / TLS channel.

And when the webservice site is in the browser, blocking the small panel by the URL bar contains the following message:

enter image description here


Here is my existing code:

Dim mySvc As New WebServices.InstantAccount mySvc.calledFunction() 


EDIT

For those who have a similar problem, read both iamkrillin's answer and my answer ... since they are both two different ways to solve the problem ... depending on which part you can control (code or certificate).

+8
security web-services iis ssl-certificate
source share
2 answers

Add this line of code somewhere before creating a client service.

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

Note: this will cause your application to accept all invalid certificates and simply continue to move. If this is unacceptable, you can attach a function to it and perform processing to determine if the certificate error is normal or not.

+11
source share

Iamkrillin had a working solution, as its code will ignore the invalid certificate and allow the application to use the web service.

In addition to this, I adjusted the certificate so that I no longer need to ignore the invalid certificate.

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

The common name and URL of the website must match. I recreated a self-signed certificate with the common name "WebServices.mycompany.vmc" and now the certificate error has disappeared. A web service is available for use, without the need for an encoder to ignore invalid certificates for the application.

+1
source share

All Articles