asp.net页面去调用通过SSL加密的webservice报错
2014-11-19 14:11
393 查看
通过C#访问webservice时遇到一个问题,首先通过对方提供的wsdl生成了调用代理类,在测试能否正常访问时,本机调试(http协议)一切正常,当访问正式环境时(https协议),总是报“基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系”InnerException信息为:根据验证过程,远程证书无效。
在网上找到解决方法:
http://social.microsoft.com/Forums/zh-CN/wcfzhchs/thread/1591a00d-d431-4ad8-bbd5-34950c39d563
依照上面的描述操作,问题解决,以作纪念
分以下三步:
1.添加引用
using System.Net;
using System.Net.Security;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
2.在生成的代理类中添加RemoteCertificateValidate函数
private static bool RemoteCertificateValidate(object sender, X509Certificate cert,X509Chain chain, SslPolicyErrors error)
{
System.Console.WriteLine("Warning, trust any certificate");
//为了通过证书验证,总是返回true
return true;
}
3.在生成的代理类的构造函数中添加
//验证服务器证书回调
ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidate;
通过C#访问webservice时遇到一个问题,首先通过对方提供的wsdl生成了调用代理类,在测试能否正常访问时,本机调试(http协议)一切正常,当访问正式环境时(https协议),总是报“基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系”InnerException信息为:根据验证过程,远程证书无效。
在网上找到解决方法:
http://social.microsoft.com/Forums/zh-CN/wcfzhchs/thread/1591a00d-d431-4ad8-bbd5-34950c39d563
依照上面的描述操作,问题解决,以作纪念
分以下三步:
1.添加引用
using System.Net;
using System.Net.Security;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
2.在生成的代理类中添加RemoteCertificateValidate函数
private static bool RemoteCertificateValidate(object sender, X509Certificate cert,X509Chain chain, SslPolicyErrors error)
{
System.Console.WriteLine("Warning, trust any certificate");
//为了通过证书验证,总是返回true
return true;
}
3.在生成的代理类的构造函数中添加
//验证服务器证书回调
ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidate;
相关文章推荐
- asp.net页面去调用通过SSL加密的webservice报错
- ASP.NET通过Global.asax和Timer定时器 定时调用WebService 运行后台代码
- PHP通过传递对象参数调用asp.net Webservice 服务
- ASP.NET通过Global.asax和Timer定时器 定时调用WebService 运行后台代码
- ASP.NET通过Global.asax和Timer定时器 定时调用WebService 运行后台代码
- 在ASP.NETAtlas中调用WebService—直接在ASPX页面上暴露WebMethod
- jquery调用asp.net webservice报错
- C/C++通过gSoap发布webservice接口,供ASP.Net网站工程调用
- 在静态页面中,通过asp.net页面调用数据库数据
- ASP.NET通过Global.asax和Timer定时器 定时调用WebService 运行后台代码
- ASP.NET通过Global.asax和Timer定时器 定时调用WebService 运行后台代码
- ASP.NET通过Global.asax和Timer定时器 定时调用WebService 运行后台代码
- asp.net 通过js调用webService注意
- 在静态页面中,通过asp.net页面调用数据库数据~
- asp.net2005中,在shtml页面中,通过asp.net页面调用数据库数据~
- asp.net 通过代理服务器调用WebService
- ASP.NET通过Global.asax和Timer定时器 定时调用WebService 运行后台代码
- ASP.NET中异步调用WebService方式!
- 通过数据捆绑将数据添加到ASP.NET 页面
- ASP.NET 2.0 AJAX中Webservice调用方法示例