首页 新闻 赞助 找找看

Web服务及数字证书的使用问题

0
悬赏园豆:15 [已解决问题] 解决于 2009-12-01 11:44

我的项目(WinForm)需要用到第三方的一个WebService服务,该服务采用了SSL加密的方式.现在,我获得了WebService服务对应的WSDL文件和一个cer数字证书文件.

请问:

1,我如何通过这个WSDL文件来访问对方的WebService服务?

2,我如何在访问时使用这个cer数字证书文件?

谢谢!

Lucker的主页 Lucker | 初学一级 | 园豆:53
提问于:2009-11-30 15:55
< >
分享
最佳答案
0

最近刚做了web服务器的数字证书,有幸搜到了LZ想要的代码,具体不记得了,思路就是new webhttprequest的时候,添加数字证书cer文件,有提供这样的方法。具体代码我还要再看下。。稍等
参考地址:How To: Call a Web Service Using Client Certificates from ASP.NET 1.1

using System.Net;
using System.Security.Cryptography.X509Certificates;

public void CallWebService()
{
// TODO: Replace with a valid path to your certificate
string certPath = @"C:\WSClientCert.cer";

// Instantiate the Web service proxy
WebSvc.math mathservice = new WebSvc.math();
mathservice.Url
= @"https://wsserver/securemath/math.asmx";

// create an X509Certificate object from the information
// in the certificate export file and add it to the
// ClientCertificates collection of the Web service proxy
mathservice.ClientCertificates.Add(
X509Certificate.CreateFromCertFile(certPath));

long lngResult = 0;
try
{
lngResult
= mathservice.Add(Int32.Parse(operand1.Text),
Int32.Parse(operand2.Text));
string result = lngResult.ToString();
}
catch(Exception ex)
{
if(ex is WebException)
{
WebException we
= ex as WebException;
WebResponse webResponse
= we.Response;
throw new Exception("Exception calling method. " + ex.Message);
}
}
}
收获园豆:15
码尔代夫iimax | 老鸟四级 |园豆:3138 | 2009-12-01 09:38
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册