我的项目(WinForm)需要用到第三方的一个WebService服务,该服务采用了SSL加密的方式.现在,我获得了WebService服务对应的WSDL文件和一个cer数字证书文件.
请问:
1,我如何通过这个WSDL文件来访问对方的WebService服务?
2,我如何在访问时使用这个cer数字证书文件?
谢谢!
最近刚做了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);
}
}
}