DotNetShipping:请求已中止:无法创建 SSL/TLS 安全通道。加拿大订单产量错误

问题描述 投票:0回答:0

我有一个基于 DotNetShipping 的自定义 dll,并且提供的运费适用于美国内部订单,但是当我尝试输入任何加拿大地址时,我的代码出错了。我不确定为什么(我也希望对此发表评论)。我一直在研究这个问题,看看我可能遗漏了什么。我确定我没有硬编码的安全协议。还将我的代码与原始运输包裹上的代码进行了比较,以找出差异。

机器环境:MS Server 2012(就地升级到 Windows Server 2019 Standard) 代码库上下文:ASP.NET 4.6.1

GetRates()
里面的函数
UPSProvider.cs
是我错误的根源。

public override void GetRates()
{
    try
    {
        ServicePointManager.Expect100Continue = true;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
        var request = (HttpWebRequest)WebRequest.Create(RatesUrl);
        request.Method = "POST";
        request.Timeout = _timeout * 1000;
        // Per the UPS documentation, the "ContentType" should be "application/x-www-form-urlencoded".
        // However, using "text/xml; encoding=UTF-8" lets us avoid converting the byte array returned by
        // the buildRatesRequestMessage method and (so far) works just fine.
        var bytes = BuildRatesRequestMessage();
        request.ContentLength = bytes.Length;
        var stream = request.GetRequestStream();
        stream.Write(bytes, 0, bytes.Length);
        stream.Close();

        ServicePointManager.Expect100Continue = true;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
        using (var resp = request.GetResponse() as HttpWebResponse)
        {
            if (resp != null && resp.StatusCode == HttpStatusCode.OK)
            {
                var xDoc = XDocument.Load(new StreamReader(resp.GetResponseStream()));
                ParseRatesResponseMessage(xDoc);
            }
        }
    }
    catch (Exception ex)
    {
        System.IO.File.WriteAllText(@"C:\Users\Public\"+ "Error-" +DateTime.Now.ToString("MMddyyyyHHmmss")+ ".txt", ex.Message);
    }
}

此捕获返回:“请求已中止:无法创建 SSL/TLS 安全通道。”

UPSProvider 在 Shipping.cs 中的函数 GetDotNetShippingUPSRates 中初始化

GetDotNetShippingUPSRates 从代码隐藏文件中调用

Shipping.aspx.cs

Shipping.aspx.cs has another catch and this one returns: 
Error in shipping.aspx.cs endPoint: System.Threading.ThreadAbortException: Thread was being aborted.
    at System.Threading.Thread.AbortInternal()
    at System.Threading.Thread.Abort(Object stateInfo)
    at System.Web.HttpResponse.AbortCurrentThread()
    at System.Web.HttpResponse.End()
    at ResponseHelper.Write(HttpResponse Response, Object Data, Boolean IsRespnseEnd, ResponseType responseType)
    at shipping.GetShippingServiceList(String shippingMethod) in C:\website\{foooooooo}.com\shipping.aspx.cs:line 626
asp.net ssl tls1.2 ups
© www.soinside.com 2019 - 2024. All rights reserved.