TIP : How to handle "SecurityNeogtiationException" *


ONLY ON DEV MACHINE - DO NOT CHECK IN OR COMMIT CODE TO SERVER


ONLY FOR DEBUGGING PURPOSES

I was trying to connect to a WCF Service and got the SecurityNegotiationException and the following Exception Message

An unhandled exception of type 'System.ServiceModel.Security.SecurityNegotiationException' occurred in mscorlib.dll

Additional information: Could not establish trust relationship for the SSL/TLS secure channel with authority 'Service Name'.

Inner Exception : {"The remote certificate is invalid according to the validation procedure."}

Since I am on my local machine I didn’t have the updated Https Cert. And because of that the Negotiation between my local machine and the service is failing.

In order to resolve this issue TEMPORARILY, I have added the following code before I initialize the service, which would ignore/skip the security validation.

ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(
delegate 
{
    return true;
});

OR

ServicePointManager.ServerCertificateValidationCallback = delegate 
{
    return true;
};

I was able to successfully debug my service.

Thank You
Vijaya Malla.
@vijayamalla