title: Getting SecurityNegotationException after some hours of using WCF Service in ASP.NET Core App
body: <p>I used Connected Service to use WSDL, that generates CurrencyClient proxy in Visual Studio.</p>
  
  <p>Then I'm registering CurrencyClient as singleton:</p>
  
  <pre><code>services.AddSingleton(() =&gt;
  {
      var binding = new BasicHttpsBinding();
      binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
  
      var address = new EndpointAddress("XXX");
  
      var client = new CurrencyClient(binding, address);
  
      client.ClientCredentials.UserName.UserName =  "XXX";
      client.ClientCredentials.UserName.Password = "XXX";
  
      return client;
  });
  </code></pre>
  
  <p>And in multiple places where I have to use this service I'm injecting CurrencyCient and using it like this:</p>
  
  <pre><code>var channel = _currencyClient.ChannelFactory.CreateChannel();
  channel.InvokeSomeMethod();
  
  channel.Close();
  </code></pre>
  
  <p>The problem is that it works for many requests, but after some hours  I got:</p>
  
  <blockquote>
    <p>System.ServiceModel.Security.SecurityNegotationException: Could not establish trust relationship for the SSL/TLS secure channel with authority XXX, 
        ---> System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. 
        ---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception. 
        ---> System.ComponentModel.Win32Exception: The buffers supplied to a function was too small.</p>
  </blockquote>
  
  <p>What I'm pretty sure, is that it's definetely the code problem, because while I got this error I can easily request the service from SoapUI or another program and got results.</p>