Https using BasicHttpBinding and ignoring certificate errors

I am using BasicHttpBinding to connect a web service hosted on a secure (https) port. To make it work, I changed Security.Mode to TransportWithMessageCredential and Security.Message to BasicHttpMessageCredentialType.Cerificate . I'm also calling

 client.ClientCredentials.ClientCertificate.SetCertificate() 

named localhost as the name of the subject.

The problem is that for unit testing, I have an unsigned certificate from a web server, and I must ignore any certificate error generated during proxy creation; but I can’t do this because I keep getting an error message telling me to "indicate certificate" . Right now, I do not know; I appreciate any help here.

+6
source share
2 answers

For the ssl server, the SecurityMode value must be set to Transport .

+6
source

You can use the following code to skip certificate verification. This creates a RemoteCertificateValidationCallback that always returns true for any certificate.

 System.Net.ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true; 
+9
source

Source: https://habr.com/ru/post/913767/


All Articles