为soap web代理启用TLS 1.2最简单的方法是什么?
问题描述:
我有一个很大的遗留解决方案,广泛使用自动生成的soap web代理。我想将其配置为仅1.2的连接支持TLS,所以我需要设置为soap web代理启用TLS 1.2最简单的方法是什么?
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
实现此目的的最简单方法是什么?代理的子分类不适用于我,因为它需要大量的代码更改。并且使用部分类不能为我提供附加配置代码的好处。
答
我选择的解决方案是调用我需要的每个上下文的初始化。它可能存在更好的解决方案,所以我打算改进我的。
首先,我定义:
public class Bootstrapper
{
private static readonly object ensureInitializationField = null;
static Bootstrapper()
{
// REFERENCE: enable TLS 1.2
ServicePointManager.SecurityProtocol =
SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
}
/// <summary>
/// Invokes the code in the static constructor.
/// </summary>
/// <remarks>
/// Code in the static constructor is called only once.
/// </remarks>
public static void EnsureInitialization()
{
Equals(ensureInitializationField, null);
}
}
后来我喜欢这个称呼它从所需的环境下(例如Global.asax.cs中):
Bootstrapper.EnsureInitialization();
你找到了一个解决方案? – NickG
我已经发布了我的解决方案。我希望它能为你提供一些线索。 – Kalitsov