The process of calling HTTPS WebService is to report "The basic connection has been closed: failed to establish a trust relationship for the SSL/TLS Security Channel ".

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.