title: Error: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel
body: <p>I have the tool which consumes a web service. I have generated a self signed cert for the web service, exported it using certificate manager to a local path.</p>
  
  <p>I'm following the following msdn code to add the certificate into by webservice. 
  <a href="https://support.microsoft.com/en-us/kb/901183" rel="nofollow">https://support.microsoft.com/en-us/kb/901183</a></p>
  
  <pre><code>string certPath = @"C:\TestData\certificate.cer";
  test.ClientCertificates.Add(X509Certificate.CreateFromCertFile(certPath));
  </code></pre>
  
  <p>Above is my code.</p>
  
  <p>I'm getting the following error.</p>
  
  <pre><code>The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
  </code></pre>
  
  <p>Stack trace:</p>
  
  <pre><code>at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request)
  at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request)
  at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
  at web_Client.testClient.testClassWebService.Add(Request request) in  C:\Workspace\Reference.cs:line 248
  at web_Client.WebClient.Add() in C:\Workspace\WebClient.cs:line 227
  </code></pre>
  
  <p>I have no idea what's going on. I'm very new to web and certificates. Please help.</p>