How can I ignore the failure of verifying the server certificate when I access WebService through HTTPS?

Source: Internet
Author: User
I helped my colleagues see a problem with accessing the remote WebService with a certificate. It has never been successful.
Use a browser to access, select a certificate, and ignore some issues. Code Wse2.0 is also installed, and x509certificate is also specified correctly (the original certificate may not have to be imported to the certificate library, but can be directly specified by path ),
However, the Code throws webexception-authenticationexception. The message in the verification exception is: the remote certificate is invalid. Check whether soaphttpclientprotocol has other certificate-related settings. If you haven't found the settings for a while, you can't do it. Please ask Google and enter "WebService, the remote certificate is invalid,
This web page helped: http://www.xue163.com/html/2008625/631589.html
Add this sentence in 2.0:
Servicepointmanager. servercertificatevalidationcallback = new system. net. Security. remotecertificatevalidationcallback (checkvalidationresult );

Public bool checkvalidationresult (Object sender, x509certificate certificate, x509chain chain, sslpolicyerrors errors)

{

// No matter what the server certificate is, it passes the verification.

Return true;
}

Add the above processing and try again. The operation is successful.

To verify whether the remote certificate is captured in the callback of checkvalidationresult, I recorded the logs in this callback function:

Public bool checkvalidationresult (Object sender, x509certificate certificate, x509chain chain, sslpolicyerrors errors)
{
Logger. Info (errors. tostring ());

// No matter what the server certificate is, it passes the verification.
Return true;
}

Well, the error message is displayed. Remote Certificate Name Mismatch.
This error message is the same as the problem that occurs in the browser, but the problem can be ignored in the browser and "continue" constantly. In the C # code, it was originally through servicepointmanager. servercertificatevalidationcallback adds a callback to provide verification.

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.