简体   繁体   English

.NET将SSL证书添加到SOAP客户端请求

[英].NET add SSL certificate to SOAP client request

Using .NET 4.0 framework I'm trying to make a server to server HTTPS SOAP service call. 使用.NET 4.0框架我正在尝试使服务器服务器HTTPS SOAP服务调用。 On the client side server, I'm trying to add a local SSL certificate so that the server receiving the call could identify me. 在客户端服务器上,我正在尝试添加本地SSL证书,以便接收呼叫的服务器可以识别我。

The certificate I'm trying to add is not from the local machine's store (the problem persists even if it is), just a (.cer) file placed as a local file on my machine. 我试图添加的证书不是来自本地机器的商店(问题仍然存在,即使它是),只是一个(.cer)文件放在我的机器上作为本地文件。

The code works fine and seems to add the certificate, but my System.Net.trace.log file keeps adding the following error for every call: "Cannot find the certificate in either the LocalMachine store or the CurrentUser store." 代码工作正常,似乎添加了证书,但我的System.Net.trace.log文件不断为每次调用添加以下错误:“无法在LocalMachine商店或CurrentUser商店中找到证书。” and the server I'm trying to call keeps telling me there's no certificate attached to my request. 我试图打电话的服务器一直告诉我,我的请求没有附加证书。 The final WebException I get is: "The request was aborted: Could not create SSL/TLS secure channel." 我得到的最后一个WebException是:“请求被中止:无法创建SSL / TLS安全通道。” My GetCertificate function: 我的GetCertificate函数:

private X509Certificate2 GetCertificate()
{
    X509Certificate2 cert;
    try
    {
        cert = new X509Certificate2("MyCertificateFoder\\MyCertificate.cer");
    }
    catch (Exception ex)
    {
        throw;
    }
    return cert;
}

Service call code: 服务电话代码:

X509Certificate2 cert = GetCertificate();
ServiceClient.ClientCertificates.Add(cert);
serviceMethodResponse = ServiceClient.ServiceMethod(serviceMethodRequest);

Will appreciate any advice. 将不胜感激任何建议。

Thanks 谢谢

The principal mistake here is that when using SSL with client authentication, a .pfx file (with client private key, certificates, certificate chains, root authority certificates) should be used. 这里的主要错误是当使用SSL与客户端身份验证时,应使用.pfx文件(包含客户端私钥,证书,证书链,根证书颁发机构证书)。

NOT the .cer file. 不是.cer文件。

This is the cause of the error. 这是错误的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM