title: SSL connection to WebService with invalid certificate workaround not working
body: <p>In my WPF application I want to make a connection with a Web-Service through HTTPS ignoring possible certificate errors, which seems to be a fairly common thing to do, from what I've been researching.</p>
  
  <p>I've found this nifty snippet:</p>
  
  <pre><code>ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
  </code></pre>
  
  <p>I've set a breakpoint on the return statement, and it is never called (tried it with a separate method too).</p>
  
  <p>I've also tried setting the following properties to false:</p>
  
  <pre><code>ServicePointManager.UseNagleAlgorithm = false;
  ServicePointManager.Expect100Continue = false; //tried true too
  ServicePointManager.CheckCertificateRevocationList = false;
  </code></pre>
  
  <p>I've also tried to create my own ICertificatePolicy with a CheckValidationResult that always returns true and attributing it to ServicePointManager.CertificatePolicy. That also hasn't worked.</p>
  
  <p>In all of these attempts, I get the following:</p>
  
  <blockquote>
    <p>The underlying connection was closed: An unexpected error occurred on
    a receive</p>
  </blockquote>
  
  <p>I've created a separate windows forms application with just three lines:</p>
  
  <pre><code>WebReference.MySebService myWebService = new WebReference.MySebService();
  ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
  bool result = myWebService.TestConnection(); 
  //TestConnection is a method in my WebService that simply returns true.
  </code></pre>
  
  <p>And it WORKED.</p>
  
  <p>What else could I try ?</p>
  
  <p>Info:  </p>
  
  <ul>
  <li>WPF application</li>
  <li>.NET 3.5</li>
  <li>The web-service is consumed through a separate class</li>
  <li>It works perfectly with regular HTTP</li>
  <li>Not using proxy</li>
  <li>Fails both on the server and with the WS on localhost</li>
  <li>The same three lines that run on my test app, won't work in my WPF app</li>
  <li>The two instances of the WebService are exactly the same (all properties, including URL)</li>
  <li>Tried deleting and re-adding the web-reference just as in my test apps.</li>
  </ul>