如何调用这需要在C#中证书的Web服务? [英] How to invoke a Web Service which requires a certificate in C#?

查看:272
本文介绍了如何调用这需要在C#中证书的Web服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要与第三方具有的.asmx Web服务进行通信。此Web服务使用https。我有所需证书(.PFX)。



在第一次尝试使用添加此服务添加服务引用中Visual Studio中,我得到了一个错误。我被导入证书到个人商店通过了这个错误。我这样做之后,我试图再次添加服务引用和它的作品。所以,现在我可以创建Web服务的一个实例。尼斯。<​​/ p>

但现在我想调用服务。当我这样做,我得到这个错误:




302通知:数字证书丢失


所以,我怎么能告诉我的服务的使用权证书?


解决方案

我终于成功地解决我的问题,因为如下:

  VAR的服务=新Service1SoapClient(); 
service.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.CurrentUser,StoreName.TrustedPublisher,X509FindType.FindByIssuerName,name_of_issuer);
((basicHttpBinding的)service.Endpoint.Binding).Security.Mode = BasicHttpSecurityMode.Transport;
((basicHttpBinding的)service.Endpoint.Binding).Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;


I need to communicate with a third party which has a .asmx web service. This web service is using https. I have the required certificate (.pfx).

When first trying to add this service using Add Service Reference in Visual Studio, I got an error. I got passed this error by importing the certificate into the Personal store. After I did that, I tried to add the Service Reference again and it works. So now I can create an instance of the web service. Nice.

But now I want to invoke the service. And when I do that I get this error:

302 Notification: Digital Certificate Missing

So how can I tell my service to use the right certificate?

解决方案

I finally managed to fix my problem as follows:

var service = new Service1SoapClient();
service.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.TrustedPublisher, X509FindType.FindByIssuerName, "name_of_issuer");
((BasicHttpBinding)service.Endpoint.Binding).Security.Mode = BasicHttpSecurityMode.Transport;
((BasicHttpBinding)service.Endpoint.Binding).Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;

这篇关于如何调用这需要在C#中证书的Web服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆