title: NTLM authentication in WCF calling .net core API
body: <p>I have a WCF service (A) that calls another WCF service (B) with the below configuration.</p>
  
  <pre><code>&lt;security mode="TransportCredentialOnly"&gt;
    &lt;transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" /&gt;
    &lt;message clientCredentialType="UserName" algorithmSuite="Default" /&gt;
  &lt;/security&gt; 
  </code></pre>
  
  <p>I'm working on calling service B from a .net core (v2.2) service. I have the below setup:</p>
  
  <pre><code>BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
  basicHttpBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
  basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
  basicHttpBinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Ntlm;
  basicHttpBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
  
  // doesn't have Default as the option. Only TripleDes
  //basicHttpBinding.Security.Message.AlgorithmSuite = SecurityAlgorithmSuite.TripleDes
  basicHttpBinding.MaxReceivedMessageSize = int.MaxValue;
  basicHttpBinding.ReceiveTimeout = new TimeSpan(250000000000);//Timespan in nanoseconds.
  
  EndpointAddress endpointAddress = new EndpointAddress("http://");
  
  customerServiceClient = new CustomerServiceClient(basicHttpBinding, endpointAddress);
  NetworkCredential networkCredential = new NetworkCredential("user", "password", "domain");
  customerServiceClient.ClientCredentials.Windows.ClientCredential = networkCredential;
  customerServiceClient.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
  </code></pre>
  
  <p>I'm getting the error: Authentication failed because the connection could not be reused. Below is the partial stack of the exception:</p>
  
  <pre><code>{"Message":"Authentication failed because the connection could not be reused.","Data":{},"InnerException":{"Message":"Authentication failed because the connection could not be reused.","Data":{},"InnerException":null,"StackTrace":"   at System.Net.Http.HttpConnection.DrainResponseAsync(HttpResponseMessage response)\r\n   at System.Net.Http.AuthenticationHelper.SendWithNtAuthAsync(HttpRequestMessage request, Uri authUri, ICredentials credentials, Boolean isProxyAuth, HttpConnection connection, HttpConnectionPool connectionPool, CancellationToken cancellationToken)\r\n   at System.Net.Http.HttpConnectionPool.SendWithNtConnectionAuthAsync(HttpConnection connection, HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)\r\n   at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)\r\n   at System.Net.Http.AuthenticationHelper.SendWithAuthAsync(HttpRequestMessage request, Uri authUri, ICredentials credentials, Boolean preAuthenticate, Boolean isProxyAuth, Boolean doRequestAuth, HttpConnectionPool pool, CancellationToken cancellationToken)\r\n   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n   at System.Net.Http.DecompressionHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n...
  </code></pre>
  
  <p>Please let me know how to get this fixed. Also, this API will be deployed into PCF.</p>
  
  <p>Thanks,
  Arun</p>