Could Not Establish Trust Relationship For The SSL/TLS Secure Channel

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

In this article we will be seeing how to resolve the following issue "The underlying connection was closed. Could not establish trust relationship for the SSL/TLS secure channel".

Problem

I was trying to create Visual Web Part in SharePoint 2010 using Visual Studio 2010 in which I need to access the HTTPS listdata.svc web service. When I was trying to access the https web service I was getting the following error

SSL/TLS secure channel

Error Message

"The underlying connection was closed. Could not establish trust relationship for the SSL/TLS secure channel".

How to resolve

Since we are trying to access the HTTPS web service we need to add the SSL to the SharePoint Trusted Root Authority.

Export an SSL certificate from windows server

Steps Involved

  1. Go to Start => Run => Type MMC and then click on Ok.

    Export an SSL certificate
     
  2. In Microsoft Management Console, Click on the File menu and then click on Add\Remove Snap-in...

    Export an SSL certificate
     
  3. In the Add or Remove Snap-ins wizard, select Certificates from the available snap-ins and then click on Add.

    Add or Remove Snap-ins wizard
     
  4. Select My user account and click on Finish.

    Add or Remove Snap-ins wizard
     
  5. Certificate will be added and click on Ok.

    SSL/TLS secure channel Certificate
     
  6. In the left pane expand Certificates, and then expand Personal.
  7. Click on Certificates folder.
  8. Right click on the certificate, click on All Tasks and then click on Export.

    SSL/TLS secure channel Certificate
    SSL/TLS secure channel Certificate
     
  9. Certificate Export Wizard will pop up, click on Next.

    Certificate Export Wizard
     
  10. In the Export File Format select DER encoded binary X.509 (.CER) format.

    select DER encoded binary
     
  11. Click on Next.
  12. In the File to Export click on browse, select the location and enter the Name.

    File to Export SSL
     
  13. Click on Save, the certificate will be saved.
  14. In the Certificate Export Wizard, click on Finish.

    Certificate Export Wizard
     
  15. You will be getting the following pop up, click on Ok.

    Certificate Export Wizard
     
  16. The certificate is exported successfully.

    Certificate Export Wizard

Add the SSL Certificate into SharePoint Trusted Root Certificate authority

  1. Go to Central Administration =>Security =>Manage Trust.

    Add the SSL Certificate into SharePoint
     
  2. In the ribbon interface, go to Trust Relationships Tab =>Manage group =>Click on New button.

    Add the SSL Certificate into SharePoint
     
  3. In the Root Certificate to trust relationship section, click on Browse.

    Add the SSL Certificate into SharePoint
     
  4. Select the certificate that we have exported.
  5. Click on Ok.
  6. Certificate is imported to the SharePoint Trusted root Authority.

    Add the SSL Certificate into SharePoint

I was able to access the HTTPS web service successfully after adding the SSL certificate to the Trusted Root Authority.