简体   繁体   English

在 Windows 7 WPF 客户端上发布异步抛出 System.Net.WebException

[英]Post async throw System.Net.WebException on Windows 7 WPF client

Query is made from a httpclient hosted in WPF control to azure server and azure server sends the results back to WPF control.从 WPF 控件中托管的 httpclient 向 azure 服务器进行查询,azure 服务器将结果发送回 WPF 控件。 On Windows 7 Os an exception is thrown when the postasync is called.在 Windows 7 操作系统上,调用 postasync 时会引发异常。 Please help me how to resolve the below exception.请帮助我如何解决以下异常。

Note : This works fine on Windows 10 client machine注意:这在 Windows 10 客户端机器上工作正常

    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.异常消息:WebException:基础连接已关闭:发送时发生意外错误。 IOException : Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. IOException : 无法从传输连接读取数据:远程主机强行关闭了现有连接。 SocketException : An existing connection was forcibly closed by the remote host SocketException : 现有连接被远程主机强行关闭

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.类型:System.Net.WebException,System,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089 消息:基础连接已关闭:发送时发生意外错误。 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.源:系统状态:SendFailure 响应:目标站点:System.IO.Stream EndGetRequestStream(System.IAsyncResult, System.Net.TransportContext ByRef) 堆栈跟踪:在 System.Net 的 System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context) 在 System.Net .Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar) 内部异常 --------------- 类型:System.IO.IOException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089消息:无法从传输连接读取数据:远程主机强行关闭了现有连接。 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)来源:System TargetSite:Void EndWrite(System.IAsyncResult) 堆栈跟踪:在 System.Net.TlsStream.EndWrite(IAsyncResult asyncResult) 在 System.Net.PooledStream.EndWrite(IAsyncResult asyncResult) 在 System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar) ) 内部异常 --------------- 类型:System.Net.Sockets.SocketException, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 消息:现有连接被强行被远程主机关闭 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)

It could be a firewall issue or a SecurityProtocol version mismatch.这可能是防火墙问题或 SecurityProtocol 版本不匹配。

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 ).或者由于 Azure TLS 默认版本是 1.2,您可以尝试将其更改为 1.0 并查看是否有任何区别(在SSL Settings )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM