1
votes

Query is made from a httpclient hosted in WPF control to azure server and azure server sends the results back to WPF control. On Windows 7 Os an exception is thrown when the postasync is called. Please help me how to resolve the below exception.

Note : This works fine on Windows 10 client machine

    var httpContent = new StringContent(value, Encoding.UTF8, "application/json");
    var queryUri = new Uri(httpClient.BaseAddress, "content/resultvalue");
    try {
        var response = await httpClient.PostAsync(queryUri, httpContent);
        response.EnsureSuccessStatusCode();
        var resultJson = await response.Content.ReadAsStringAsync();
        var result = JsonConvert.DeserializeObject<Result>(resultJson);
    } catch (Exception e) {
        //report the exception to the user
    }

Exception Messages: WebException : The underlying connection was closed: An unexpected error occurred on a send. IOException : Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. SocketException : An existing connection was forcibly closed by the remote host

Type : System.Net.WebException, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Message : The underlying connection was closed: An unexpected error occurred on a send. Source : System Status : SendFailure Response : TargetSite : System.IO.Stream EndGetRequestStream(System.IAsyncResult, System.Net.TransportContext ByRef) Stack Trace : at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context) at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar) Inner Exception --------------- Type : System.IO.IOException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Message : Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. Source : System TargetSite : Void EndWrite(System.IAsyncResult) Stack Trace : at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult) at System.Net.PooledStream.EndWrite(IAsyncResult asyncResult) at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar) Inner Exception --------------- Type : System.Net.Sockets.SocketException, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Message : An existing connection was forcibly closed by the remote host Source : System ErrorCode : 10054 SocketErrorCode: ConnectionReset NativeErrorCode: 10054 TargetSite : Int32 EndReceive(System.IAsyncResult) Stack Trace : at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult) at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)

1
it works fine for windows 10 client, windows 7 and windows 10 are in the same network. - rags45
i checked the securityprotocol on .net 4.7 on windows it is default. Is it possible to tell what does it mean, - rags45
@Leo Thanks for the solution, it worked like a charm for Windows 7 - Catalin Iancu

1 Answers

2
votes

It could be a firewall issue or a SecurityProtocol version mismatch.

Try this:

System.Net.ServicePointManager.SecurityProtocol = 
   SecurityProtocolType.Tls | 
   SecurityProtocolType.Tls11 | 
   SecurityProtocolType.Tls12; 

or as Azure TLS default version is 1.2, you could try to change it to 1.0 and see if that makes any difference (in SSL Settings).