【问题标题】:Post async throw System.Net.WebException on Windows 7 WPF client在 Windows 7 WPF 客户端上发布异步抛出 System.Net.WebException
【发布时间】:2019-01-07 15:52:06
【问题描述】:

从托管在 WPF 控件中的 httpclient 向 azure 服务器进行查询,然后 azure 服务器将结果发送回 WPF 控件。在 Windows 7 操作系统上,调用 postasync 时会引发异常。请帮助我如何解决以下异常。

注意:这在 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
    }

异常消息: WebException:底层连接已关闭:发送时发生意外错误。 IOException:无法从传输连接读取数据:现有连接被远程主机强行关闭。 SocketException : 现有连接被远程主机强行关闭

类型:System.Net.WebException,系统,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089 消息:底层连接已关闭:发送时发生意外错误。 来源:系统 状态:发送失败 回复 : TargetSite : System.IO.Stream EndGetRequestStream(System.IAsyncResult, System.Net.TransportContext ByRef) 堆栈跟踪:在 System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult,TransportContext& 上下文) 在 System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar) 内部异常 --------------- 类型:System.IO.IOException,mscorlib,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089 消息:无法从传输连接读取数据:远程主机强制关闭现有连接。 来源:系统 目标站点:无效 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,系统,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089 消息:现有连接被远程主机强行关闭 来源:系统 错误代码:10054 SocketErrorCode:连接重置 本机错误代码:10054 目标站点:Int32 EndReceive(System.IAsyncResult) 堆栈跟踪:在 System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult) 在 System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)

【问题讨论】:

  • windows 10 客户端运行良好,windows 7 和 windows 10 在同一个网络中。
  • 我在 Windows 上检查了 .net 4.7 上的安全协议,它是默认的。能不能说清楚是什么意思,
  • @Leo 感谢您的解决方案,它就像 Windows 7 的魅力一样

标签: c# .net wpf azure ssl


【解决方案1】:

可能是防火墙问题或 SecurityProtocol 版本不匹配。

试试这个:

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

或者由于 Azure TLS 默认版本是 1.2,您可以尝试将其更改为 1.0,看看是否有任何不同(SSL Settings)。

【讨论】:

  • 您发布的代码我可以在哪里添加?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-09
  • 1970-01-01
  • 2016-06-24
相关资源
最近更新 更多