Is It Possible To Call HTTPClient From SSIS Script Task?

Paduck, Daniel 0 Reputation points
2024-06-06T17:37:15.7233333+00:00

Hi,

I have the following code in my SSIS script task:

User's image

However, if I put a break point on the client.SendAsysnc, the code goes right by it. Then if I take out the break point and do a break point after execution, the SSIS project just stops running.

Has anyone been successful at using HTTPClient from SSIS? I am using VS 2019 C# coding.

Thanks,

Daniel

SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,502 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Michael Taylor 50,506 Reputation points
    2024-06-06T17:48:01.7566667+00:00

    Yes you can call HttpClient inside a script task. That is the only way to make REST calls.

    There are a couple of problems here. Firstly your ObtainToken method is marked async but it returns void. That means there is no way for the asyn call to actually wait. Hence your SendAsync call is being triggered but nobody is waiting for it to complete. Async must (almost always) be combined with a return type of Task. Without that return type the first async method you call immediately returns from the function, the caller isn't waiting and therefore the caller continues executing and your method is effectively ignored. Fix it by changing the return type.

    public async Task ObtainToken()
    {
       //Rest of code
    }
    

    The second problem we can only guess at but SSIS script tasks are not async. I assume you're calling this method inside your script's Main method. You cannot use async/await in Main for the same reasons you cannot use it here, the function returns void and async void doesn't work. So when you call an async method from non-async code you have to explicitly wait for the results. This is generally not recommended but in the rare cases (such as here) it is needed you must do so.

    //Assuming the caller is Main which is void Main ()
    //Wait for the work to complete
    ObtainToken().GetAwaiter().GetResult();
    

    The above code will block Main until the async work is completed inside the called method.

    0 comments No comments

  2. Olaf Helper 42,746 Reputation points
    2024-06-06T17:53:21.2733333+00:00

    I have the following code in my SSIS script task:

    That's not code as it, it's a screenshot. Please post the code as code.

    client.SendAsysnc

    You can not really use Async methods i a SSIS script task.

    0 comments No comments

  3. ZoeHui-MSFT 34,756 Reputation points
    2024-06-07T06:24:10.11+00:00

    Hi @Paduck, Daniel,

    You may take a reference to below thread.

    SSIS package C# script task to make https call using httpClient

    Regards,

    Zoe Hui


    If the answer is helpful, please click "Accept Answer" and upvote it.

    0 comments No comments