1

I used Connected Service to use WSDL, that generates CurrencyClient proxy in Visual Studio.

Then I'm registering CurrencyClient as singleton:

services.AddSingleton(() =>
{
    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;
});

And in multiple places where I have to use this service I'm injecting CurrencyCient and using it like this:

var channel = _currencyClient.ChannelFactory.CreateChannel();
channel.InvokeSomeMethod();

channel.Close();

The problem is that it works for many requests, but after some hours I got:

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.

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.

1 Answer 1

1

The error mainly indicates that the trust relationship could not be established between the server and the client since the server communicates over HTTPS. We should express the attitude to the server certificate when we try to connect and communicate with the server.
Commonly, if we trust the server identity, we are supposed to install the server certificate in local client Root CA (Certificate storage).
enter image description here
Alternatively, we could also add the below code in Dotnetframework project for convenience.

ServicePointManager.ServerCertificateValidationCallback = delegate
            {
                return true;
            };

As for the Asp.net Core project, we could utilize the below code.

ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
            client.ClientCredentials.ServiceCertificate.SslCertificateAuthentication =
            new X509ServiceCertificateAuthentication()
            {
                CertificateValidationMode = X509CertificateValidationMode.None,
                RevocationMode = X509RevocationMode.NoCheck
            };

The communication would be established properly over HTTPS since the above validation process indicates that the client trusts the server identity.
Feel free to let me know if there is anything I can help with.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for you answer, but the connection actually works really well, it just starts to show this error after some hours of working so I believe the SSL connection should be ok? If not then how would it work for hte first 5-6 hours?
First, I suggest you try it and check if the aforementioned work is configured(whether the client has installed the certificate). Then I suspect that there is something wrong with the prerequisite what establishes the communication between the client and the server. learn.microsoft.com/en-us/dotnet/framework/network-programming/…
Besides, please refer to below discussion, wish it is useful to you. github.com/dotnet/wcf/issues/2499 github.com/dotnet/wcf/issues/3405

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.