【问题标题】:Rest Calls fail in SSIS休息呼叫在 SSIS 中失败
【发布时间】:2020-03-11 00:49:46
【问题描述】:

我尝试从 REST API 中提取一些数据并将其输入 MS SQL Server。 出于调试目的,我在 C# 控制台应用程序中准备了所有内容,它运行良好。

现在我将我的代码复制到一个 SSIS 脚本任务中,但我似乎无法连接到该服务。 它可以编译,但在执行时我得到一个带有错误的空响应(它不会抛出异常,错误是响应对象中的内容):

IRestClient restClient = new RestClient();
IRestRequest restRequest = new RestRequest("SomeURL");

restRequest.AddParameter("login", "Someuser");

IRestResponse restResponse = restClient.Get(restRequest);

当我检查响应对象时,调试器会告诉我以下信息:

Status = SendFailure
Message = "Die zugrunde liegende Verbindung wurde geschlossen: Unerwarteter Fehler beim Senden.."
StackTrace = "   at System.Net.HttpWebRequest.GetResponse()\r\n   at RestSharp.Http.<ExecuteRequest>g__GetRawResponse|181_1(WebRequest request)\r\n   at RestSharp.Http.ExecuteRequest(String httpMethod, Action`1 prepareRequest)"

将 Visual Studio 2019 与 RestSharp 和 Newtonsoft.Json 库结合使用。 我在同一个 SSIS 项目中也有一个 SOAP-Client 脚本任务,并且该任务有效。

编辑:我按照@KeithL 的建议尝试了使用 webClient ,但我基本上得到了同样的错误。

【问题讨论】:

  • 我几乎总是使用命名空间 System.Net 中的网络客户端;在 SSIS 中很难使用外部 dll。如果您有要反序列化的基本 JSON,我还建议您使用 System.Web.Script.Serialization.JavaScriptSerializer()
  • 不幸的是,JSON 部分并不是那么简单。例如,它需要一些复杂的报告配置来发送和返回一个包含动态字段和所有内容的非常复杂的结构。所以我宁愿不要“步行”做这一切。目前我使用控制台应用程序,我从 SSIS 调用它来写入 csv 然后导入它。尽管如此,在绕过整个安装 dll 到 gac 障碍并让它编译之后,我觉得我已经完成了 90%。还是谢谢你的回答!
  • 如果我想使用 Nuget for Json,我肯定会转向控制台应用程序。我喜欢 app.quicktype.io/#l=cs&r=json2csharp 的 Quicktype 用于复杂 Json 类的类构建

标签: c# ssis restsharp


【解决方案1】:

使用 webClient...

编辑:有时您需要在代码中指定:

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

   System.Net.WebClient wc = new System.Net.WebClient();
   wc.Headers.Add("login", "Someuser");
   string json = wc.DownloadString("SomeUrl");

【讨论】:

  • 我试过这个,我基本上得到了同样的错误:$exception {"Die zugrunde liegende Verbindung wurde geschlossen: Unerwarteter Fehler beim Senden.."} System.Net.WebException
  • @Daniel 有时您必须添加 2 个服务点管理器子句。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-10-01
  • 1970-01-01
  • 2011-10-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多