[英]Load a certificate to sign a SOAP envelope in C# with WCF
I try to load a x509 certificate to use in a WCF client. 我尝试加载x509证书以在WCF客户端中使用。 for this i use the SetDefaultCertificate
function but this function throw a exception. 为此,我使用SetDefaultCertificate
函数,但是此函数引发异常。
var clientWS = new WS_eFacturaSoapPortClient();
clientWS.ClientCredentials.ServiceCertificate.SetDefaultCertificate(
StoreLocation.CurrentUser, StoreName.My,
X509FindType.FindBySubjectKeyIdentifier, "79852b4fab95e8cd1f6e36167bbb895bd4cbe767");
The exception: 例外:
Cannot find the X.509 certificate using the following search criteria: 使用以下搜索条件找不到X.509证书:
StoreName 'My', StoreLocation 'CurrentUser', FindType StoreName'我',StoreLocation'CurrentUser',FindType
'FindBySubjectKeyIdentifier', FindValue 'FindBySubjectKeyIdentifier',FindValue
'79852b4fab95e8cd1f6e36167bbb895bd4cbe767'. '79852b4fab95e8cd1f6e36167bbb895bd4cbe767'。
But if I do this... 但是如果我这样做
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(); }
The certificate is founded. 证书成立。
What i do wrong?, is posible add the x509Certificate2 to the ClientCredentials? 我做错了什么,可以将x509Certificate2添加到ClientCredentials吗?
I changed the FindType
to FindBySerialNumber
and it works. 我将FindType
更改为FindBySerialNumber
并且可以正常工作。
clientWS.ClientCredentials.ServiceCertificate.SetDefaultCertificate(
StoreLocation.CurrentUser, StoreName.My,
X509FindType.FindBySerialNumber, "0cf43655217b8853e2df0b931d2c352afa93d9");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.