使用C#中的证书进行SOAP身份验证

时间:2017-03-10 10:47:21

标签: c# web-services ssl soap wsdl

我需要使用证书对SOAP服务器进行身份验证。

我使用“添加服务引用”在Visual Studio / C#中创建了一个SOAP客户端来导入.wsdl文件,现在我可以使用服务类soap.ServiceReference1.SerWSPortClient。 使用mmc.exe我将证书添加到本地计算机和当前用户。 我能够找到证书并将其添加到客户端类,但是当我调用服务方法时,我收到了SSL错误。

这是我的代码:

    soap.ServiceReference1.SerWSPortClient client = new soap.ServiceReference1.SerWSPortClient();

    client.ClientCredentials.ClientCertificate.Certificate = cert;
    client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerOrChainTrust;
client.ClientCredentials.ServiceCertificate.Authentication.RevocationMode = X509RevocationMode.Offline;

    soap.ServiceReference1.ResponseGetList list;
    list = client.getList();

这是错误:

 System.ServiceModel.Security.SecurityNegotiationException: Could not establish secure channel for SSL/TLS with authority 'ser.ver.com'. ---> System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel. 
   at System.Net.HttpWebRequest.GetResponse() 
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)...

我做错了什么?

不幸的是我无法访问服务器代码。

我想也许我需要在客户端类中添加一些额外的信息才能使身份验证成功。我正在编写此代码的客户端告诉我他必须使用安全卡,并且他必须输入PIN码才能访问浏览器中的服务器URL(例如http://ser.ver.com/api/wsdl?)以便检索wsdl文件他给我。当他试图运行我的代码时,他得到了和我一样的错误。我既没有卡也没有PIN码,当我尝试导航到服务器URL时,我收到此错误,尽管我手动为Chrome添加了证书。

ser.ver.com didn’t accept your login certificate, or one may not have been provided. Try contacting the system admin. ERR_BAD_SSL_CLIENT_AUTH_CERT

0 个答案:

没有答案