Could not establish trust relationship for the SSL/TLS secure channel

"Could not establish trust relationship for the SSL/TLS secure channel " That problem comes when you try to call  https webservices in your web application. for solving this problem:

1. you need to install server certificate.
2. Alternate method is create static class which always validate to server certificate and returns true

you can do this by using this code:

using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;


public static class WebConnect
{
    /// <summary>
    /// Sets the cert policy.
    /// </summary>
    public static void SetCertificatePolicy()
    {
        ServicePointManager.ServerCertificateValidationCallback
                   += RemoteCertificateValidate;
    }

    /// <summary>
    /// Remotes the certificate validate.
    /// </summary>
    private static bool RemoteCertificateValidate(
       object sender, X509Certificate cert,
        X509Chain chain, SslPolicyErrors error)
    {
        // trust any certificate!!!
         return true;
    }
}

before making connection to service, use  SetCertificatePolicy method and your problem resolved.
Ebook Download
View all
Learn
View all