加载证书以使用WCF在C#中签署SOAP信封
我尝试加载x509证书以在WCF客户端中使用。为此,我使用了加载证书以使用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
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");
帮助了我