国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

zt:Consuming Webservices over HTTPS (SSL)

2024-07-21 02:25:07
字體:
來源:轉載
供稿:網友
when webservices are used, a common concern is security: soap messages are transferred in plain text over the network, so anyone with a sniffer could intercept the soap message and read it. in my opinion this could happen also to binary data, but probably it requires a little bit more hacker skills. so a solution is to use https (ssl) instead of http, so the communication is encrypted. to accomplish this, you need to get and install a certificate (issued by a certificate authority) on your webserver. in a production environment you would buy a certificate from verisign or another well known ca, or you would install your own ca, which is a component of windows server. if you only want to play with https, ssl and certificates or your project is in the development phase, you can also generate a test certificate using the makecert.exe tool (included in the .net framework sdk). after that you have to add this certificate to a website in iis, and set a port which https should use.

when you browse to a https site, you probably get a dialog window asking you if you want to trust the certificate provided by the webserver. so the responsibility of accepting the certificate is handled by the user. let's get back to the webservice scenario, if you want to invoke a webservice located on a webserver which uses ssl and https there is a problem. when you make the call from code, there is no dialog window popping up, and asking if you trust the certificate (luckily because this would be pretty ugly in server-side scenarios); probably you'll get following exception:
an unhandled exception of type 'system.net.webexception' occurred in system.dll

additional information: the underlying connection was closed: could not establish trust relationship with remote server.

but there is a solution for this problem, you can solve this in your code by creating your own certificatepolicy class (which implements the icertificatepolicy interface). in this class you will have to write your own checkvalidationresult function that has to return true or false, like you would press yes or no in the dialog window. for development purposes i've created the following class which accepts all certificates, so you won't get the nasty webexception anymore:
public class trustallcertificatepolicy : system.net.icertificatepolicy
{
public trustallcertificatepolicy()
{}

public bool checkvalidationresult(servicepoint sp,
x509certificate cert,webrequest req, int problem)
{
return true;
}
}

as you can see the checkvalidationresult function always returns true, so all certificates will be trusted. if you want to make this class a little bit more secure, you can add additional checks using the x509certificate parameter for example. to use this certificatepolicy, you'll have to tell the servicepointmanager to use it:
system.net.servicepointmanager.certificatepolicy = new trustallcertificatepolicy();
this must be done (one time during the application life cycle) before making the call to your webservice.
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 东明县| 乐都县| 堆龙德庆县| 普宁市| 怀远县| 乐安县| 陈巴尔虎旗| 兴化市| 金沙县| 德清县| 富锦市| 宜宾县| 寻乌县| 大英县| 清原| 滨海县| 南阳市| 商城县| 界首市| 河曲县| 鄂温| 灌云县| 顺昌县| 南召县| 加查县| 石狮市| 呼伦贝尔市| 尉氏县| 宾川县| 贵南县| 无极县| 沙坪坝区| 额尔古纳市| 绥阳县| 托克逊县| 岢岚县| 大安市| 博爱县| 五大连池市| 广丰县| 江陵县|