SoapHttpClientProtocol 和 TLS 1.2 - 客户端和服务器无法通信,因为它们不具备通用算法

SoapHttpClientProtocol and TLS 1.2 - The client and server cannot communicate, because they do not possess a common algorithm

SO上有很多关于这个的帖子,我已经搜索过了,但仍然没有解决方案。我希望有人能指出我正确的方向。

我们现在需要使用 TLS 1.2 连接到远程提供商。所以我已经安装了 Windows Server 2016 并根据需要进行了配置:

我知道远程服务器是 运行 TLS 1.2 并且它支持突出显示的密码。

我们使用由提供商提供的 WSDL 生成的 C# 代理 class 连接到远程端点 - 在他们将端点转换为 TLS (System.Web.Services.Protocols.SoapHttpClientProtocol) 之前。

当我使用代理连接时出现异常,内部异常为 "The client and server cannot communicate, because they do not possess a common algorithm"。

我在任何地方都看不到 ServicePointManager.SecurityProtocol 所以我假设 .NET 正在选择 TLS 1.2,因为它是唯一启用的协议?不知道它是如何进行加密的。

有人可以告诉我如何尝试解决这个问题吗?如果可能,我不想重新生成 WSDL 代理 class。

如果您的客户端应用程序是针对 .NET Framework 4.5.2 或更低版本编译的,则默认情况下 ServicePointManager.SecurityProtocol 会初始化为 SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls(仅限 SSL 3.0 和 TLS 1.0),因此它不会'无法连接到需要 TLS 1.2 的远程服务器。

有几种方法可以让您的客户端应用程序使用 TLS 1.2:

  • 针对 .NET Framework 4.6 或更高版本重新编译您的客户端应用程序。 (在 Visual Studio 中,打开项目的 属性 页面,转到应用程序选项卡,然后更改目标框架。)
  • 在客户端计算机上,运行 RegEdit.exe,转到 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ .NETFramework\v4.0.30319,添加名为 SchUseStrongCrypto 的 DWORD(32 位)值,并将其设置为 1。(此标志导致 ServicePointManager.SecurityProtocol 被初始化为 Tls | Tls11 | Tls12。)
  • 当您的客户端应用程序启动时,打开 TLS 1.2:ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;

无需重新生成您的代理 class,因为它不负责协商 TLS 协议或密码。

我在从连接到 Web 服务的网站中删除 TLS 1.0 时遇到了这个问题。 对我来说,这是一个 httpRuntime,它停留在 Web 服务 web.config 中的 4.5.1 上。该服务已更改为 4.6.1,将 web.config 中的 httpRuntime 版本更改为 4.6.1 修复了该问题。 该网站试图为网络服务设置 TLS,但只有 1.2 和 1.1 可用。 Web 服务仅支持 1.0,因此导致错误。