简体   繁体   English

如何绕过Windows CE中的SSL证书错误

[英]How to bypass SSL certificate error in Windows CE

I want to bypass the SSL certificate error of web service in Windows CE. 我想绕过Windows CE中Web服务的SSL证书错误。

There are many solutions for .net Windows applications such as; .net Windows应用程序有许多解决方案,例如;

Bypass invalid SSL certificate errors when calling web services in .Net 在.Net中调用Web服务时绕过无效的SSL证书错误

But in windows ce I can not import ServicePointManager library. 但是在Windows CE中,我无法导入ServicePointManager库。

So is there another way to do this in Windows CE ? 那么在Windows CE中还有另一种方法可以做到这一点吗?

You can in fact use the ServicePointManager in the CF as well. 实际上,您也可以在CF中使用ServicePointManager。 First, create a policy that accepts everything, as so: 首先,创建一个接受所有内容的策略,如下所示:

public class TrustAllCertificatePolicy : ICertificatePolicy
{
    public TrustAllCertificatePolicy()
    {
    }

    public bool CheckValidationResult(ServicePoint sp,
        X509Certificate cert, WebRequest req, int problem)
    {
        return true;
    }
}

To use this class, you should run the following code once per application session (each time the application is started; the TrustAllCertificatePolicy instance will be used each time an SSL connection is made), and before you make any Web requests (preferably on application startup). 要使用此类,您应该在每个应用程序会话中一次运行以下代码(每次启动应用程序;每次建立SSL连接时都将使用TrustAllCertificatePolicy实例),并且在发出任何Web请求之前(最好在应用程序启动时) )。

System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();

This solution is equivalent to answering yes to any security messages that would normally appear in a browser. 此解决方案等效于对通常会在浏览器中显示的任何安全消息回答“是”。

More info here 更多信息在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM