Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SSIS中的Rest调用失败_C#_Ssis_Restsharp - Fatal编程技术网

C# SSIS中的Rest调用失败

C# SSIS中的Rest调用失败,c#,ssis,restsharp,C#,Ssis,Restsharp,我尝试从RESTAPI中提取一些数据,并将其输入MS SQL Server。 出于调试目的,我在一个C#控制台应用程序中准备了所有东西,它运行良好 现在我将代码复制到SSIS脚本任务中,似乎无法连接到该服务。 它进行编译,但在执行时,我得到一个带有错误的空响应(它不会引发异常,错误是响应对象中的错误): 当我检查响应对象时,调试器会告诉我以下信息: IRestClient restClient = new RestClient(); IRestRequest restRequest = new

我尝试从RESTAPI中提取一些数据,并将其输入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)"
状态=发送失败
Message=“我的朋友们:我的朋友们……”
StackTrace=“at System.Net.HttpWebRequest.GetResponse()\r\n at RestSharp.Http.g_ugetrawresponse | 181_1(WebRequest请求)\r\n at RestSharp.Http.ExecuteRequest(字符串httpMethod,操作'1 prepareRequest)”
将VisualStudio2019与RestSharp和Newtonsoft.Json库一起使用。 我在同一个SSIS项目中还有一个SOAP客户端脚本任务,该任务可以工作

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

使用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");
正在使用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");

我几乎总是使用命名空间System.Net中的webclient;在SSI中很难使用外部DLL。如果您有基本的JSON进行反序列化,我还建议您使用System.Web.Script.Serialization.JavaScriptSerializer(),不幸的是,JSON部分并不是那么简单。例如,它需要一些复杂的报告配置来发送和返回一个非常复杂的结构,包括动态字段和所有字段。所以我不想“步行”完成这一切。目前我使用console应用程序,我从SSIS调用它写入csv,然后导入它。尽管如此,在克服了从dll到gac的整个安装障碍并将其编译之后,我感觉自己已经达到了90%。还是谢谢你的回答!如果我想使用Nuget作为Json,我肯定会转向控制台应用程序。我喜欢Quicktype at用于复杂Json类的类构建,我几乎总是使用命名空间System.Net中的webclient;在SSI中很难使用外部DLL。如果您有基本的JSON进行反序列化,我还建议您使用System.Web.Script.Serialization.JavaScriptSerializer(),不幸的是,JSON部分并不是那么简单。例如,它需要一些复杂的报告配置来发送和返回一个非常复杂的结构,包括动态字段和所有字段。所以我不想“步行”完成这一切。目前我使用console应用程序,我从SSIS调用它写入csv,然后导入它。尽管如此,在克服了从dll到gac的整个安装障碍并将其编译之后,我感觉自己已经达到了90%。还是谢谢你的回答!如果我想使用Nuget作为Json,我肯定会转向控制台应用程序。我喜欢Quicktype at用于复杂Json类的类构建。我尝试过这个,基本上得到了相同的错误:$exception{“Die zugrunde liegende Verbindung wurde geschlossen:unerwarter Fehler beim Senden..”}System.Net。WebException@Daniel有时您必须添加两个服务点管理器条款。我尝试了这个,我基本上得到了相同的错误:$exception{“Die zugrunde liegende Verbindung wurde geschlossen:unerwarter Fehler beim Senden..”}System.Net。WebException@Daniel有时您必须添加两个服务点管理器子句。