title: CommunicationException in client-service integration test
body: <p>I'm making an integration tests for my WCF service, in which my test client is making requests to self hosted service.</p>
  
  <p>My WCF service setup:</p>
  
  <pre><code>var binding = new BasicHttpBinding {Security = {Mode = BasicHttpSecurityMode.Transport}};
  var endpointAddress = new EndpointAddress("https://localhost:44398/MyService.svc");
  var host = new ServiceHost(typeof(MyService), endpointAddress.Uri);
  host.AddServiceEndpoint(typeof(WcfServices.Contracts.IMyService),
  binding, endpointAddress.Uri);
  host.Open();
  </code></pre>
  
  <p>And my client call:</p>
  
  <pre><code>var client = new MyServiceClient(binding, endpointAddress);
  
  // Act
  
  Contract.MyResult result;
  try
  {
      result = actMethod.Invoke(sut);
  }
  finally
  {
      client.Close();
      if (host.State == CommunicationState.Opened)
          host.Close();
      else
          host.Abort();
  }
  </code></pre>
  
  <p>Before executing tests, I run this PowerShell script:</p>
  
  <pre><code>$whoami = WHOAMI
  netsh http add urlacl url=https://+:44398/MyService.svc/ user=$whoami
  </code></pre>
  
  <p>Everything works just fine on my local machines, but when it's built with my pipeline in Azure DevOps, and it comes to running this particular test, I get:</p>
  
  <blockquote>
    <p>System.ServiceModel.CommunicationException : An error occurred while making the HTTP request to <a href="https://localhost:44398/MyService.svc" rel="nofollow noreferrer">https://localhost:44398/MyService.svc</a>. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server.</p>
    
    <p>---- System.Net.WebException : The underlying connection was closed: An unexpected error occurred on a send.</p>
    
    <p>-------- System.IO.IOException : Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.</p>
    
    <p>------------ System.Net.Sockets.SocketException : An existing connection was forcibly closed by the remote host</p>
  </blockquote>
  
  <p>Also, I've tried adding this to my test:</p>
  
  <pre><code>if (ServicePointManager.SecurityProtocol == (SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls))
      ServicePointManager.SecurityProtocol =
          SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
  </code></pre>
  
  <p>Without any change.</p>
  
  <p>I get that it may have something to do with the fact I've never used any certificate in pipeline, though I wonder why would it work without one on my local machine then. Also, I don't really know how to properly set up one in pipeline. Could someone give me a hand with solving this issue?</p>