Posts Tagged ‘technology’

Hello WCF Service? NO ENDPOINT LISTENING – is your SSL self-signed?

No Comments »

Testing a WCF service that uses a self-signed certificate which will throw this exception:

There was no endpoint listening at https://www.domainname.com/servicename.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

The inner exception is : The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

Basically, this is a security measure to ensure that the client uses or explicitly circumvents the certificate check.  In order to explicitly circumvent this check, the client should use this code before calling any of the service functions:

A. This is the verbose method

1.  Code to conditional enforce validation check (we added this to a static utility class):

public static bool ValidateRemoteCertificate( object sender,

X509Certificate certificate, 

X509Chain chain, 

SslPolicyErrors policyErrors )
 {
    if (Convert.ToBoolean(

      ConfigurationManager.AppSettings["IgnoreSslErrors"]))
    {
      return true;
    }
      else
    {
      return policyErrors == SslPolicyErrors.None;
    }
  }

2.  Code to call ValidateRemoteCertificate in the handler for RemoteCertificateValidationCallback (we put this code in our test fixtures).  Put this code before your first call to the service:

//Ignore SSL cert validation issues if config is set 
ServicePointManager.ServerCertificateValidationCallback += 

new System.Net.Security.RemoteCertificateValidationCallback(TestUtils.ValidateRemoteCertificate);

B. This is a more compact call, but if you need to call in multiple places, less manageable

1.  Put this code before your first call to the service:

//Trust any certificate 
System.Net.ServicePointManager.ServerCertificateValidationCallback = 

((sender, certificate, chain, sslPolicyErrors) => true);