C# 在SSIS中执行HTTP get操作以从API获取信息
我正在开发一个SSIS包,以便从API获取一些信息。SSIS中是否有任何组件或扩展可用于执行HTTP请求或响应操作。我的。它有两个字段ID和date。我试图通过提供ID来获取“日期”字段 我不熟悉c#和SSIS。请让我知道我是否应该尝试使用脚本组件,或者SSIS中是否有其他扩展来执行此操作 在SSIS中使用脚本组件是我尝试过的 以下是我在参考了这篇文章之后所做的尝试C# 在SSIS中执行HTTP get操作以从API获取信息,c#,.net,json,web-services,ssis,C#,.net,Json,Web Services,Ssis,我正在开发一个SSIS包,以便从API获取一些信息。SSIS中是否有任何组件或扩展可用于执行HTTP请求或响应操作。我的。它有两个字段ID和date。我试图通过提供ID来获取“日期”字段 我不熟悉c#和SSIS。请让我知道我是否应该尝试使用脚本组件,或者SSIS中是否有其他扩展来执行此操作 在SSIS中使用脚本组件是我尝试过的 以下是我在参考了这篇文章之后所做的尝试 public override void CreateNewOutputRows() { 字符串serviceDate=Varia
public override void CreateNewOutputRows()
{
字符串serviceDate=Variables.TaskID;
字符串wUrl=”https://virtserver.swaggerhub.com/Monish/Disenrollment/1.0.0/inventory?searchString=“+服务日期;
尝试
{
WorkGroupMetric[]outPutMetrics=GetWebServiceResult(wUrl);
foreach(outPutMetrics中的var度量)
{
Output0Buffer.AddRow();
Output0Buffer.DisenrollmentDate=metric.CN;
}
}
捕获(例外e)
{
FailComponent(例如ToString());
}
}
私有WorkGroupMetric[]GetWebServiceResult(字符串wUrl)
{
HttpWebRequest httpWReq=(HttpWebRequest)WebRequest.Create(wUrl);
HttpWebResponse httpWResp=(HttpWebResponse)httpWReq.GetResponse();
WorkGroupMetric[]jsonResponse=null;
尝试
{
//测试连接
if(httpWResp.StatusCode==HttpStatusCode.OK)
{
Stream responseStream=httpWResp.GetResponseStream();
字符串jsonString=null;
//设置jsonString
使用(StreamReader=新StreamReader(responseStream))
{
jsonString=reader.ReadToEnd().Replace(“\\”,”);
reader.Close();
}
//解除JSON的序列化
JavaScriptSerializer sr=新的JavaScriptSerializer();
jsonResponse=sr.Deserialize(jsonString.Trim(“”);
}
//输出连接错误消息
其他的
{
FailComponent(httpWResp.StatusCode.ToString());
}
}
捕获(例外e)
{
FailComponent(例如ToString());
}
返回jsonResponse;
}
web服务任务只支持http请求,您发布的代码中的URL使用https。除了脚本任务之外,还有另一个选项,我发现它更容易实现(在大多数情况下),使用“执行进程”任务启动powershell,然后执行脚本下载数据。您是否尝试过发布的代码?该服务是否有“类型”参数?如果有,则可能更容易处理xml结果。web服务任务仅支持http请求,发布的代码中的URL使用https、 除了脚本任务之外,我发现还有一个选项更容易实现(在大多数情况下),使用“执行进程”任务启动powershell,然后执行脚本下载数据。您是否尝试过发布的代码?该服务是否具有“类型”参数?如果是,则可能更容易处理xml结果
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;
}