C# service cannot connect to web service after server upgrade

I am using HttpClient.PostAsync to call a REST web service (Unified Endpoint Management, but I doubt that is relevant) on a remote (internal LAN) server. The call is throwing an exception as follows:

10/15/2020 5:05:25 AM An error occurred while sending the request.
10/15/2020 5:05:25 AM    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
10/15/2020 5:05:25 AM The underlying connection was closed: An unexpected error occurred on a send.
10/15/2020 5:05:25 AM    at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context)
   at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)
10/15/2020 5:05:25 AM Authentication failed because the remote party has closed the transport stream.
10/15/2020 5:05:25 AM    at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
   at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)

The error seems to indicate some kind of TLS error. The certificate is issued by an internal CA which is trusted through Group Policy. I can do the exact same call by pasting the JSON data, URL and headers into Postman, and it works. I can open the server URL in Firefox without a problem, although on Edge I get an error “Turn on TLS 1.0, TLS 1.1, and TLS 1.2 in the Advanced settings,” but doing that changes nothing either on the .NET service on in Edge. I have also done the same in .NET by specifying the TLS options to 1.0, 1.1 and 1.2 manually. I’ve done likewise for SSL 2.0 and SSL 3.0, but nothing changes.

According to the software vendor, it should be using TLS 1.2. I cannot change much server side as it’s proprietary software.

Any ideas? I need to get this working again, but the code hads’t changed since before the server was updated and the REST API specification remains the same (confirmed by Postman).

I’m running the code on .NET Framework 4.6.1 (ASP.NET). The flow is a bit strange as I have a web interface running on PHP (Laravel) on one server, which sends a call to a .NET web service on another server (this is where I’m running into the problem), that server in turns calls a Tomcat server and also performs tasks in .NET.


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Thank you for everyone who offered assistance with this problem.

I solved this problem by disabling “TLS Cipher Suite Order” in the Local Group Policy, and rebooting the server – both steps were required to solve the problem.

The problem was not with the TLS version, as indicated in the message, but with the cipher used. It seems that the server was using a cipher not listed in the custom order specified by the policy.

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x