RestRequest 在本地工作,但不是来自 azure "The request was aborted: Could not create SSL/TLS secure channel."

RestRequest works local but not from azure "The request was aborted: Could not create SSL/TLS secure channel."

当我 运行 我的应用程序在本地主机上时它工作正常但是当我将它发布到 Azure 时我的请求停止工作。 收到错误:“请求被中止:无法创建 SSL/TLS 安全通道。”

我有一个调用外部商业 Soap 的应用程序-API。外部 API 需要在我发出请求时传递客户端证书,它还需要将我的 IP 地址列入白名单。

商业 API 已将我从我的应用 service/properties/outgoing 获得的 IP 和 Azure 中的虚拟 IP 地址列入白名单

我已将我的客户端证书文件 (.p12) 添加到我的解决方案中的一个文件夹中,当检查上传到 azure 的文件时,我也可以在那里看到它。

使用 RestSharp,我的请求如下所示:

   private string RequestToBv(string pXml)
    {            
        X509Certificate2 cert = new X509Certificate2(bvCertificatePath, bvCertificatePassword);

        var client = new RestClient(mXmlApiUrl); //mXmlApiUrl = url to endpoint
        client.Timeout = -1;
        client.ClientCertificates = new X509CertificateCollection() { cert };
        var request = new RestRequest(Method.POST);
        request.AddHeader("Content-Type", "application/xml");
        request.AddParameter("application/xml", pXml, ParameterType.RequestBody);

        IRestResponse response = client.Execute(request);

        if (response.StatusCode == HttpStatusCode.OK)
        {
            return response.Content;
        }

        return "";
    }

在 Azure 中调试时,我收到 StatusCode = 0 和错误消息:“请求已中止:无法创建 SSL/TLS 安全通道。”

在 Whosebug 中搜索答案后,我必须在我的方法顶部添加以下代码行:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
        ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => true;

但我仍然收到相同的错误响应。

我是否需要在 Azure 中设置任何设置或以某种方式在 Azure 上安装我的客户端证书?

评论后的附加信息:

我必须做的是将我的 .p12 证书文件转换为 crt 文件,将其导入 Azure,然后在我的代码中使用 X509Store 来获取它。 之后握手成功