【问题标题】:Connecting to RESTful site using Script Task使用脚本任务连接到 RESTful 站点
【发布时间】:2018-04-04 19:36:18
【问题描述】:

我一直在尝试HttpWebRequest 对象的各种组合(在 SSIS 中)以连接到 web 服务地理编码站点,以拉回单个地理编码信息,但没有运气。这是一个 JSON 响应和https URL。

        string wUrl = "https://geocoding.geo.census.gov/geocoder/geographies/onelineaddress?address=1600+Pennsylvania+Ave+NW,+Washington,+DC,+20500&benchmark=Public_AR_Current&vintage=4&format=json";
        X509Certificate cert = X509Certificate.CreateFromCertFile("C:\\Users\\kwhauser\\geocode.cer");

        HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create(wUrl);
        //WebRequest httpWReq = WebRequest.Create(wUrl);
        //httpWReq.Method = "GET";
        httpWReq.ClientCertificates.Add(cert);
        //httpWReq.ContentType = "application/json";

        //ServicePointManager.ServerCertificateValidationCallback = (s, cert, chain, ssl) => true;
        //ServicePointManager.Expect100Continue = true;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;

        //HttpWebResponse httpWResp = (HttpWebResponse)httpWReq.GetResponse();
        //HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
        try
        {
            HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
            //WebResponse response = httpWReq.GetResponse();
            //Stream responseStream = response.GetResponseStream();

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
            if (ex.InnerException != null)
                MessageBox.Show(" InnerException: " + ex.InnerException.Message);

        }

无论我尝试从文件加载证书还是使用回调证书,我仍然会收到相同的错误消息:

System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.

DotNet 框架版本是 4.7。该站点需要 TLS12。我已向 chrome 添加了简单的 REST 客户端扩展,并成功测试了 URL。它在GetResponse 上失败。

我错过了什么?

【问题讨论】:

  • 您是否尝试过使用ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;?这会奏效。

标签: c# https ssis-2012


【解决方案1】:
System.Net.ServicePointManager.SecurityProtocol = (System.Net.SecurityProtocolType)3072;

【讨论】:

  • 唯一的选择是Tls 或Ssl3。没有其他选择。如果我注释掉该行并且根本不使用它,同样的错误消息。
  • 这出乎意料。
  • 您的 SQL 版本是 SQL Server 2012 SP2 11.0.5644.2 还是更高版本?
  • 我几乎可以保证您需要更新您的 SSIS 数据工具/服务器
  • 谢谢迈克尔!!就是这样!!一旦我终于更新了 SSDT,它就会第一次运行。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-02-23
  • 2012-05-25
  • 2020-06-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-02
相关资源
最近更新 更多