【问题标题】:Load a certificate to sign a SOAP envelope in C# with WCF使用 WCF 在 C# 中加载证书以签署 SOAP 信封
【发布时间】:2015-08-09 13:29:39
【问题描述】:

我尝试加载 x509 证书以在 WCF 客户端中使用。为此,我使用SetDefaultCertificate 函数,但该函数抛出异常。

var clientWS = new WS_eFacturaSoapPortClient();
clientWS.ClientCredentials.ServiceCertificate.SetDefaultCertificate(
    StoreLocation.CurrentUser, StoreName.My, 
    X509FindType.FindBySubjectKeyIdentifier, "79852b4fab95e8cd1f6e36167bbb895bd4cbe767");

例外:

使用以下搜索条件找不到 X.509 证书:
StoreName 'My',StoreLocation 'CurrentUser',FindType
'FindBySubjectKeyIdentifier', FindValue
'79852b4fab95e8cd1f6e36167bbb895bd4cbe767'。

但如果我这样做......

X509Certificate2 cert = null;
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
try
{
    store.Open(OpenFlags.ReadOnly);
    X509Certificate2Collection col = store.Certificates.Find(
        X509FindType.FindBySubjectKeyIdentifier, "79852b4fab95e8cd1f6e36167bbb895bd4cbe767", true);
    cert = col[0];
}
//  Cerrar el store
finally { store.Close(); }

证书成立。

我做错了什么?是否可以将 x509Certificate2 添加到 ClientCredentials?

【问题讨论】:

    标签: c# wcf soap


    【解决方案1】:

    我将FindType 更改为FindBySerialNumber,它可以工作。

    clientWS.ClientCredentials.ServiceCertificate.SetDefaultCertificate(
        StoreLocation.CurrentUser, StoreName.My, 
        X509FindType.FindBySerialNumber, "0cf43655217b8853e2df0b931d2c352afa93d9");
    

    this post 帮助了我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-09
      • 2013-06-02
      • 1970-01-01
      • 2014-10-18
      • 1970-01-01
      • 2011-06-01
      • 2018-03-22
      相关资源
      最近更新 更多