如何在与thiry party服务通信时将.pfx文件中的用户证书正确附加到soap请求?

时间:2017-02-24 10:08:07

标签: c# wcf soap certificate

我使用C#来做到这一点。我使用第三方API通过SOAP请求与服务进行通信,他们希望我从他们发给我们的每个SOAP请求的.pfx文件中附加客户端证书。

var serv = new MonetaSoapService.PublicSoapClient();
X509Certificate2 cert = new X509Certificate2("certificate.pfx","password", X509KeyStorageFlags.PersistKeySet);
serv.ClientCredentials.ClientCertificate.Certificate = cert;
LogInWs f = serv.LogIn(""); // LogIn is an operation on the server, it returns a LogInWs object, which contains info of the success or failure of the log in operation.
Console.WriteLine(f.ErrorDescription);

然后会给出一个

  

"未知证书错误"

从服务器发回。

我还看到.pfx文件实际上包含3个证书(root,intermediate和client),通过在集合中导入它。在仅发送客户端证书时,它表示它未知,但当我尝试发送其中任何一个时,它表示不允许匿名连接,所以,我猜服务器就好像证书不是首先是在那里。我应该以某种方式将所有三个作为一个链发送出去吗?

1 个答案:

答案 0 :(得分:0)

在我的情况下,我首先安装证书,然后使用这样的代码,我就能得到回复。

oClient = new YourClientObject();
oClient.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.My, X509FindType.FindBySubjectName, "Certificate Name");
oClient.Open();