Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF error: "The X.509 certificate CN=localhost chain building failed ..."

I'm getting this error while attempting to make my WCF client and server talk to each other.

The X.509 certificate CN=localhost chain building failed. The certificate that was used has a trust chain that cannot be verified. Replace the certificate or change the certificateValidationMode. A certificate chain processed, but terminated in a root certificate which is not trusted by the trust.

Everything works perfectly if I turn SSL certificates off.

like image 303
Contango Avatar asked Nov 23 '10 13:11

Contango


2 Answers

I fixed the problem by turning off validation in my code like this:

client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = 
System.ServiceModel.Security.X509CertificateValidationMode.None;

Where client is an instance of my service reference.

like image 135
Zane Avatar answered Sep 30 '22 06:09

Zane


There is a problem with your certificate (I suppose you use self-signed cert) WCF tries to verify all the chain of issuers and expects, that finally chain would end on root trusted authority. To disable that check you could add such line to app.config branch. But this "crutch" shouldn't be used in production serviceBehaviors/behavior/serviceCredentials/clientCertificate

<authentication certificateValidationMode="PeerOrChainTrust" revocationMode="NoCheck" />
like image 29
The Smallest Avatar answered Sep 30 '22 07:09

The Smallest