I am testing an early release of a WCF web service I have created. On the client side when I use VS to \'add service reference\' that all works.
But when I try to us
Set the CertificatePolicy PRIOR to initializing your WCF service on the client. Here's how (just make a call to the SetCertificatePolicy() method once)
///
/// Sets the cert policy.
///
private static void SetCertificatePolicy()
{
ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate;
}
///
/// Certificate validation callback
///
private static bool ValidateRemoteCertificate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error)
{
if (error == SslPolicyErrors.None)
{
return true; // already determined to be valid
}
switch (cert.GetCertHashString())
{
// thumbprints/hashes of allowed certificates (uppercase)
case "066CF9CAD814DE2097D368F22D3A7D398B87C4D6":
case "5B82C96685E3A20079B8CE7AFA32554D55DB9611":
Debug.WriteLine("Trusting X509Certificate '" + cert.Subject + "'");
return true;
default:
return false;
}
}