.NET 4.5.1中的WCF客户端:使用WebRequest时如何启用TLS 1.2? [英] WCF Client in .NET 4.5.1: How to enable TLS 1.2 when WebRequest is used?

查看:357
本文介绍了.NET 4.5.1中的WCF客户端:使用WebRequest时如何启用TLS 1.2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的.net WCF客户端,即WebRequest调用,已编译为Windows EXE,运行在Win2012-R2上,拒绝连接到仅显示TLS 1.2的Web服务器。



我们知道Win2012和.NET 4.5x支持TLS 1.2



当服务器使用TLS 1.0及更高版本时,我们没有问题。仅当我们连接的服务器具有DISABLED TLS 1.0、1.1以及SSL2和SSL3时,才会出现此问题。服务器仅公开TLS 1.2。 Chrome和firefox(在Win 7及更高版本上)可以很好地连接到服务器(没有任何警告或SSL问题)。



服务器证书为%100 OK。 / p>

问题是WebRequest在这种情况下无法连接。



我们需要在代码中设置什么,因此我们对WebRequest的使用将连接到可能运行TLS 1.2、1.1、1.0和/或SSL v3的系统?

解决方案

虽然不容易弄清楚,但所需的属性是:


System.Net.ServicePointManager.SecurityProtocol


可以在WCF环境中禁用和启用TLS级别。



此外,您还可以看到WCF当前设置为使用:

  Console.WriteLine(System.Net.ServicePointManager.SecurityProtocol。 ToString()); 

由于:
如何禁用SSL后备功能,而仅将TLS用于.NET中的出站连接? (缓解狮子狗)


Our .net WCF Client, the WebRequest call, compiled to a windows EXE, running on Win2012-R2, refuses to connect to a web server that surfaces ONLY TLS 1.2

We know that Win2012 and .NET 4.5x support TLS 1.2

We have no problems when the server surfaces TLS 1.0 and up. The problem is only seen when the server we connect to has DISABLED TLS 1.0, 1.1 and SSL2 and SSL3. The Server ONLY surfaces TLS 1.2. Chrome and firefox (on Win 7 and higher) connect fine to the server (no warnings or SSL issues of any kind).

The server certificate is %100 OK.

The problem is that WebRequest fails to connect in this situation.

What do we need to set in code so that our use of WebRequest will connect to systems that may run TLS 1.2, 1.1, 1.0, and/or SSL v3?

解决方案

While not easy to figure out, the needed property is:

System.Net.ServicePointManager.SecurityProtocol

This can be used to disable and enable TLS levels in the WCF environment.

Further, you can see what WCF is currently set to using:

Console.WriteLine(System.Net.ServicePointManager.SecurityProtocol.ToString());

With thanks to: How do I disable SSL fallback and use only TLS for outbound connections in .NET? (Poodle mitigation)

这篇关于.NET 4.5.1中的WCF客户端:使用WebRequest时如何启用TLS 1.2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆