Today, I encountered a problem when I access WebService through C #. First, I generated a call proxy class through the WSDL provided by the other party. When I tested whether the access was normal, I accessed the formal environment https://api.xxx.xx and everything was normal, when the access test environment is https://apitest.xxx.xxx, The innerexception message "Basic Connection closed: failed to establish trust for SSL/TLS Secure Channel" is always: the remote certificate is invalid based on the authentication process.
Find the solution on the Internet:
Http://social.microsoft.com/Forums/zh-CN/wcfzhchs/thread/1591a00d-d431-4ad8-bbd5-34950c39d563
Follow the steps described above to solve the problem.
Perform the following three steps:
1. Add reference
Using system. net;
Using system. net. Security;
Using system. Security. authentication;
Using system. Security. cryptography. x509certificates;
2. Add the remotecertificatevalidate function to the generated proxy class.
Private Static bool remotecertificatevalidate (Object sender, x509certificate cert,
X509chain chain, sslpolicyerrors error ){
// Trust any certificate !!!
System. Console. writeline ("Warning, trust any certificate ");
// Always returns true to pass the certificate verification
Return true;
}
3. Add it to the constructor of the production proxy class
Servicepointmanager. servercertificatevalidationcallback + = remotecertificatevalidate; // verify that the server certificate callback is automatically verified