1

I have quite a cumbersome problem. I am trying to Post a Webjob in Azure via SSIS. The following request works in my test-application which is a console application.

public static void Main(string[] args)
    {

            string ApiUrl = "HTTPS";
            string call = "triggeredwebjobs/JOB NAME/run";
            string result = string.Empty;
            string userPswd = "USER" + ":" + "PASSWORD";
            userPswd = Convert.ToBase64String(Encoding.Default.GetBytes(userPswd));
            var response = new HttpResponseMessage(HttpStatusCode.NotFound);
            try
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(ApiUrl);
                    client.Timeout = TimeSpan.FromMinutes(30);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", userPswd);
                    response = client.PostAsync(call, new StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json")).Result;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }


    }

The above code is successful and makes a post request to targeted webjob in Azure in order to trigger it.

When I put the below code inside an SSIS package and try to run it from Visual Studio it does not work.

public void Main()
    {
        // TODO: Add your code here
        try
        {

            string ApiUrl = "HTTPS";
            string call = "triggeredwebjobs/JOB NAME/run";
            string result = string.Empty;
            string userPswd = "USER" + ":" + "PASSWORD";
            userPswd = Convert.ToBase64String(Encoding.Default.GetBytes(userPswd));
            var response = new HttpResponseMessage(HttpStatusCode.NotFound);
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(ApiUrl);
                client.Timeout = TimeSpan.FromMinutes(30);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", userPswd);
                response = client.PostAsync(call, new StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json")).Result;
            }


        }
        catch (Exception ex)
        {
            Dts.Events.FireError(0, "ERROR", ex.Message, null, 0);
            Dts.TaskResult = (int)ScriptResults.Failure;
        }
        Dts.TaskResult = (int)ScriptResults.Success;
    }

I get Status code 404.

Any idea on how to correct this issue? I am stuck on this and I have started to go in circles trying to fix it. The only thing I can think of is network-issues but I do not know how to verify this.

halfer
  • 18,701
  • 13
  • 79
  • 158
konkret
  • 43
  • 3

1 Answers1

0

I found a solution for this issue: Need to add SecurityProtocol

Citation from the solution:

The key is adding security protocol and apply all types: ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | Tls32 |.. This resolved the issue

A more robust solution can be found here: Configure ServicePointManager.SecurityProtocol through AppSettings

Dharman
  • 21,838
  • 18
  • 57
  • 107
JayWayze
  • 118
  • 5