Daniel
Daniel

Reputation: 426

Rest Calls fail in SSIS

I try to pull some data from a REST API and get it into MS SQL Server. For debugging purposes I prepared everything in a C# console app, and it workes fine.

Now I copied my code to an SSIS Script task and I cant seem get a connection to the service. It compiles, but upon execution I get a null response with an error (it does not throw an exception, the error is what´s in the response object):

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

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

IRestResponse restResponse = restClient.Get(restRequest);

The Debugger tells me the following when I inspect the response object:

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)"

Using Visual Studio 2019 with RestSharp and Newtonsoft.Json Libraries. I also have a SOAP-Client script task in the same SSIS Project and that one works.

Edit: I tried as @KeithL suggested, using webClient and I basically get the same error.

Upvotes: 0

Views: 930

Answers (1)

KeithL
KeithL

Reputation: 5594

Using webClient...

EDIT: Sometimes you need to specify this in your code:

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");

Upvotes: 2

Related Questions