现在的位置: 首页 > 综合 > 正文

如何调用基于Basic authentication/Digest authentication/windows authencation验证模式并且需提供客户端certificate的web service?

2012年06月14日 ⁄ 综合 ⁄ 共 947字 ⁄ 字号 评论关闭

前言:

当客户端掉用承载在IIS中基于basic authentication/digest authentication等等非anonymous验证模式时,客户端必须提供相应的credential.

主要注意点:

1. 如何generate 代理类

在利用wsdl command时,必须提供连接到web service上的用户名和密码才能generate proxy,其语法如下:

wsdl  http://webservice-uri/webservice.asmx /username:yourusername /password:yourpassword

2.如何在client application递交client credential和certificate.

为了提交client 的credential, 我们必须创建一个客户端的credential,然后随proxy instance一起递交到server端以便验证,如下所时:

Service1 proxy = new Service1();

System.Net.NetworkCredential credential = new System.Net.NetworkCredential("yourusername", "yourpassword", "yourdomain");

 proxy.Credentials = credential;

然后我们需要指定客户端的certificate(public-key 部分),如下: 

 System.Security.Cryptography.X509Certificates.X509Certificate cert = new System.Security.Cryptography.X509Certificates.X509Certificate("yourcertificate-publickey.cer");

proxy.ClientCertificates.Add(cert);

这样的话,客户端就提供了credential和certificate并一起提交之server了 :)当然以上所作的一切,前提条件是web service 所在的server是配置成了基于basic/digest authencation+certificate模式。

抱歉!评论已关闭.