title: System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel
body: <p>I have a windows service in a VM. It is calling an API hosted in another server. When I call that api from my windows service, it is giving me error saying :</p>
  
  <blockquote>
    <p>System.Net.WebException: The underlying connection was closed: Could
    not establish trust relationship for the SSL/TLS secure channel. --->
    System.Security.Authentication.AuthenticationException: The remote
    certificate is invalid according to the validation procedure.</p>
  </blockquote>
  
  <p>Now I know that if I add this line before calling the api, it will work fine.</p>
  
  <pre><code>System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
  </code></pre>
  
  <p>But I do not want to change my code and deploy it again. Is there any way I can do something in the VM where windows service is hosted, like trusting the certificate or something , which will resolve this?  </p>
  
  <p>Any help in this regard is really helpful. Thanks.  </p>
  
  <p>I know this question is asked multiple time, but all the solutions require me to either change in the server where api is hosted or change my code to add above line. I'm looking for a solution where I can change in the client machine rather than anywhere else.</p>