tags:

views:

354

answers:

1
+2  Q: 

SSL Error + WCF

Exact duplicate of
SSL error RemoteCertificateNameMismatch
SSL error RemoteCertificateNameMismatch

I am using WCF for the client to access service. I am trying to access the endpoint with TLS (https). I have certificates with both private and public keys.

If I have the end point of the service to have the host name same as the certificate name ("Issued To"), then i am able to access the service from the client.

If the names of the "issued to" and end point domain name are different i get the error "Could not establish trust relationship for the SSL/TLS secure channel with authority". I have added the certificates to "Trusted Root", "Personal" and "trusted People". In my service i have used "PeerOrChainTrust".

Please let me know if anybody has any idea on this

+1  A: 

In that case, you need to define the trust policy for the server on client side,

Call SetCertPolicy once before you make any call to the services.

using System.Net;
using System.Security.Cryptography.X509Certificates;
     public static void SetCertPolicy()
     {
      ServicePointManager.ServerCertificateValidationCallback += RemoteCertValidate;
     }

     private static bool RemoteCertValidate( object sender, X509Certificate cert, X509Chain chain,
      SslPolicyErrors error )
     {
      // trust any cert!!!
      return true;
     }
codemeit