有一个 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/