0

I try to load a x509 certificate to use in a WCF client. for this i use the SetDefaultCertificate function but this function throw a exception.

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:
StoreName 'My', StoreLocation 'CurrentUser', FindType
'FindBySubjectKeyIdentifier', FindValue
'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?

Fjodr
  • 919
  • 13
  • 32
Maske
  • 824
  • 2
  • 17
  • 35

1 Answers1

0

I changed the FindType to FindBySerialNumber and it works.

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

this post helped me.

Community
  • 1
  • 1
Maske
  • 824
  • 2
  • 17
  • 35