c# - 如何使 Windows 商店应用程序与 TLS 1.2 一起工作?

标签 c# wcf ssl windows-store-apps

有一个 Windows 应用商店应用程序 8.1 通过 WCF 连接到 Web 服务。最近在服务器上设置了 TLS 1.2,因此应用程序停止工作。这里是异常(exception)

An error occurred while making the HTTP request to https://services.companyname.com This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server.

即使是一个简单的网络请求

WebRequest request = WebRequest.Create(SERVER_URL_PROD);
WebResponse response = await request.GetResponseAsync();

返回以下内容

An exception of type 'System.Net.WebException' occurred in mscorlib.dll but was not handled in user code

Additional information: The underlying connection was closed: An unexpected error occurred on a send.

那么如何让 Windows 应用商店应用程序与 TLS 1.2 一起工作呢?

更新

如果

,上面的代码可以在控制台应用程序 (.NET 4.5) 中运行
 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

但是 ServicePointManager 不适用于 Windows 应用商店应用

更新 2

此外,该代码在 ServicePointManager 不可用的 Windows Phone 8.1 中有效。

最佳答案

我已经处理了 Web 应用程序的 TLS 1.2 问题,正如 OP 所提到的,System.Net.ServicePointManager 的简单解决方案在 Windows 应用商店应用程序中不起作用。

解决方法是使用 Windows.Web.Http 而不是 System.Net.Http,如 MSDN forum 中所述发布。

关于c# - 如何使 Windows 商店应用程序与 TLS 1.2 一起工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30867183/

相关文章:

java - 如何确保Android应用程序正在访问真实服务器

apache - 两个 VirtualHosts 通过 https(运行 Redmine 等)

c# - c# 中的面向对象问题

c# - .Net 核心网络 API

c# - foreach 循环中奇怪的 IEnumerable 行为

wcf - 使用安全模式="TransportWithMessageCredential"测试WCF服务wsHttpBinding

jquery - 通过使用 jQuery 解析 sessionID 从 WCF 服务访问 session 变量

c# - 无法在 Linq to Entity 查询中构造实体或复杂类型

c# - 参数序列化——指定命名空间

.net - 使用 .NET 后端在 Angular App 中启用 SSL