Udostępnij za pośrednictwem


Cannot find the X.509 certificate , load cert WCF

I just had an interesting problem trying to load a cert for my WCF service. The cert was installed perfectly into both the Local machine and current user store.

No matter what I could do I couldnt get the WCF service to load the aqppropriate client certificate using its thumprint. It always just couldnt find it. It turns out that its actually quite easy and that I was making one silly mistake that I didnt see anywhere else online. The certs thumbprint requires you to remove all the spaces.

WSHttpBinding sampleBinding= new WSHttpBinding();

sampleBinding.Security.Mode = SecurityMode.Transport;

sampleBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;

EndpointAddress ea = new EndpointAddress(" https://myerviceaddress.svc");

WsClient wsClient =  new WsClient(sampleBinding, ea);

wsClient.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.LocalMachine,StoreName.My, X509FindType.FindByThumbprint, "6827A9E09EEE24C6290C808ACEDD000FFC825345");

 

If you want the certs properties so that you can just get them as it expects you could also just load them like below and print to intermediate window or look them up through the locals and copy the values in..

X509Certificate2 actualCert = new X509Certificate2(@"C:\Certpath\cert.pfx", "password");

The certmanager does this but I find this easier when your programming it exactly as it should expect

Comments