前言:
作者在制作一个Winform窗体工具时,在解决方案中调用了其他网页的链接Service Reference,但是在程序运行后,提示错误,如图2所示。
----------------------------------------------------------------------------------------解决方法如下----------------------------------------------------------------
查找网上的解决方案后,总结如下:
1、添加using应用
我是直接在当前.cs文件中添加。
using System.Net.Security;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
2、重载CheckValidationResult方法,返回true;
作者在当前类中直接重载的
public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
return true;
}
3、在创建ServiceReference.AppFileServiceSoapClient对象前添加代码行1,其中参数就是CheckValidationResult为重载的名称
System.Net.ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
ServiceReference.AppFileServiceSoapClient WebRef = new ServiceReference.AppFileServiceSoapClient("AppFileServiceSoap");