无法为SSL / TLS C#Web服务客户端建立安全通道

tpb*_*afk 1 c# wpf ssl webservice-client

我有一个wpf应用程序,并且在相同的基本url上调用4个Web服务(书面Java),并且在我安装google chrome之前它一直运行良好。我安装了chrome,但出现了这个错误:

无法为SSL / TLS C#Web服务建立安全通道

我没有写另一个代码。那只是我安装了chrome然后删除了chrome但没有用,并且尝试了系统还原,卸载eset smart security并清理了所有Windows(8.1种单一语言)证书的情况。想办法。这是我的网络服务呼叫者

public string call(string url, string json)
{
    try
    {
        var webrequest = (HttpWebRequest)WebRequest.Create(url);
        var key = JsonConvert.SerializeObject(LoginService.SessionData.SessionKey);
        UTF8Encoding uTF8Encoding = new UTF8Encoding();
        byte[] requestBytes = uTF8Encoding.GetBytes(json);
        WebClient client = new WebClient();

        webrequest.Method = "POST";
        webrequest.Headers.Add("SESSION_KEY", LoginService.SessionData.SessionKey);
        webrequest.ContentType = "application/json";
        webrequest.ContentLength = requestBytes.LongLength;
        Stream requestStream = webrequest.GetRequestStream();//here the exception
        requestStream.Write(requestBytes, 0, requestBytes.Length);

        using (var response = webrequest.GetResponse())
        using (var reader = new StreamReader(response.GetResponseStream()))
        {
            var responseBuf = reader.ReadToEnd();
            String responseJson = Convert.ToString(responseBuf);
            return responseJson;
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
    return null;
}
Run Code Online (Sandbox Code Playgroud)

Cro*_*der 5

据我观察,过去几个月中有大量服务正在关闭SSL和/或较旧的TLS版本,以缓解其中固有的安全性问题。

在AppDomain中的任何位置,您都可以强制连接使用TLS 1.2,如下所示:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

OR如果还需要支持较旧的版本,也可以将多个版本组合在一起:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12