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.