惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
罗磊的独立博客
SecWiki News
SecWiki News
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Schneier on Security
IT之家
IT之家
博客园 - 聂微东
T
The Exploit Database - CXSecurity.com
Recorded Future
Recorded Future
大猫的无限游戏
大猫的无限游戏
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Vercel News
Vercel News
G
GRAHAM CLULEY
D
DataBreaches.Net
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
SegmentFault 最新的问题
博客园_首页
雷峰网
雷峰网
T
Tenable Blog
Spread Privacy
Spread Privacy
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
酷 壳 – CoolShell
酷 壳 – CoolShell
Cisco Talos Blog
Cisco Talos Blog
V
Visual Studio Blog
J
Java Code Geeks
博客园 - Franky
The Cloudflare Blog
Apple Machine Learning Research
Apple Machine Learning Research
C
CERT Recently Published Vulnerability Notes
T
Threatpost
Google DeepMind News
Google DeepMind News
F
Fortinet All Blogs
P
Privacy International News Feed
T
Threat Research - Cisco Blogs
T
The Blog of Author Tim Ferriss
V
Vulnerabilities – Threatpost
Recent Announcements
Recent Announcements
Blog — PlanetScale
Blog — PlanetScale
Security Latest
Security Latest
U
Unit 42
M
MIT News - Artificial intelligence
Y
Y Combinator Blog
K
Kaspersky official blog
有赞技术团队
有赞技术团队
B
Blog
腾讯CDC

博客园 - 亮小猪

荣耀之光,王者同行,云聚一堂,2010年MVP Open Day小记 让Windows 7的互联网电视帮您更简单地度过周末 微软MSDN论坛上海聚会 敏捷Scrum实战营,免费报名(上海1月23日、北京1月30日) 微软中文技术论坛2010新年聚会,邀您齐欢乐 快来加入微软技术社区精英计划,提升个人品牌 中国的第一封电子邮件 群星闪耀的两岸三地2009 MVP Open Day 2009 China MVP Open Day 第一天 上海GTUG第二届线下活动预告 Silverlight 3 has Released! 成都生活 VisualSVN Server issue: Server sent unexpected return value (403 Forbidden) in response to MKACTIVITY 微软论坛2009全新奉献,全新打造技术自测系列活动:一起学习Silverlight IE7下用ajax动态填充select框的一个问题 分享:下周今天,微软技术创新日在成都!欢迎参加~ 分享:微软客户端技术免费培训@成都 二维码新工具:Microsoft Tag (beta)初体验 用Hook Script阻止空日志信息提交到Subversion
Web Service via SSL - 亮小猪
亮小猪 · 2009-03-06 · via 博客园 - 亮小猪

如果你调用一个启用了SSL的Web服务,你会收到如下错误:

"The underlying connection was closed: Could not establish trust relationship with remote server."

这是因为客户端没有接受服务端证书,在添加服务的时候,有个提示框出来让你确认证书,但是在程序调用时是没有办法去选择的,那么我们可以创建一个证书策略来解决这个问题。

 System.Net.ICertificatePolicy接口定义了自定义证书验证策略,我们就实现这个接口,然后实现自己的CheckValidationResult方法就可以了。对了,没那么复杂的,看代码:

Code
public class TrustAllCertificatePolicy : System.Net.ICertificatePolicy
{
 
public TrustAllCertificatePolicy()
 {}
public bool CheckValidationResult(ServicePoint sp,
  X509Certificate cert,WebRequest req, 
int problem)
 {
  
return true;
 }
}

对的,return true就可以了。

我们在创建Web Service的代理类实例前,创建我们自己的证书验证策略类就好了:

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

然后再调用Web Service的方法就没有问题了。

from here.