【问题标题】:Perform HTTP get operation in SSIS to fetch information from an API在 SSIS 中执行 HTTP get 操作以从 API 获取信息
【发布时间】:2017-06-08 19:22:49
【问题描述】:

我正在开发一个 SSIS 包以从 API 获取一些信息。我可以在 SSIS 中使用任何组件或扩展来执行 HTTP 请求或响应操作。我的 API is in JSON format。它有两个字段 ID 和日期。我正在尝试通过提供 ID 来获取“日期”字段。

我是 C# 和 SSIS 的新手。请让我知道我是否应该尝试使用脚本组件,或者 SSIS 中是否有任何替代扩展来执行此操作。

在 SSIS 中使用脚本组件是我尝试过的。

这是我在参考this 文章后尝试过的。

public override void CreateNewOutputRows()
{
    string serviceDate = Variables.TaskID;
    string wUrl = "https://virtserver.swaggerhub.com/Monish/Disenrollment/1.0.0/inventory?searchString=" + serviceDate;

    try
    {
        WorkGroupMetric[] outPutMetrics = GetWebServiceResult(wUrl);

        foreach( var metric in outPutMetrics)
        {
            Output0Buffer.AddRow();
            Output0Buffer.DisenrollmentDate = metric.CN;


        }
    }
    catch (Exception e)
    {
        FailComponent(e.ToString());
    }

}

private WorkGroupMetric[] GetWebServiceResult(string wUrl)
{
    HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create(wUrl);
    HttpWebResponse httpWResp = (HttpWebResponse)httpWReq.GetResponse();
    WorkGroupMetric[] jsonResponse = null;

    try
    {
        //Test the connection
        if(httpWResp.StatusCode == HttpStatusCode.OK)
        {
            Stream responseStream = httpWResp.GetResponseStream();
            string jsonString = null;

            //Set jsonString
            using (StreamReader reader = new StreamReader(responseStream))
            {
                jsonString = reader.ReadToEnd().Replace("\\", "");
                reader.Close();
            }

            //Desearialize our JSON
            JavaScriptSerializer sr = new JavaScriptSerializer();

            jsonResponse = sr.Deserialize<WorkGroupMetric[]>(jsonString.Trim('"'));

        }
        //Output connection error message
        else
        {
            FailComponent(httpWResp.StatusCode.ToString());
        }
    }
    catch (Exception e)
    {
        FailComponent(e.ToString());
    }
    return jsonResponse;
}

【问题讨论】:

    标签: c# .net json web-services ssis


    【解决方案1】:

    web服务任务只支持http请求,你贴的代码中的url使用https。除了我发现更容易实现的脚本任务之外,还有另一个选项(在大多数情况下),使用“执行进程”任务来启动 powershell,然后执行脚本来下载数据。您是否尝试过您发布的代码?该服务是否有“类型”参数?如果是这样,使用 xml 结果可能会更容易。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-05
      • 1970-01-01
      • 2021-10-28
      • 1970-01-01
      相关资源
      最近更新 更多