Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
加载证书以使用WCF在C#中签署SOAP信封_C#_Wcf_Soap - Fatal编程技术网

加载证书以使用WCF在C#中签署SOAP信封

加载证书以使用WCF在C#中签署SOAP信封,c#,wcf,soap,C#,Wcf,Soap,我尝试加载x509证书以在WCF客户端中使用。为此,我使用了SetDefaultCertificate函数,但该函数会引发异常 var clientWS = new WS_eFacturaSoapPortClient(); clientWS.ClientCredentials.ServiceCertificate.SetDefaultCertificate( StoreLocation.CurrentUser, StoreName.My, X509FindType.FindBy

我尝试加载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?

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

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