I have a web api in an ASE and an associated web job. I am trying to call this web api from the web job but it always fails with winhttpexception: a security error has occurred. I have put in all the tls related settings but still getting the error. Any suggestions on the error? Also is there a way to share code between WebJob and web api?
Asked
Active
Viewed 507 times
1

Joey Cai
- 18,968
- 1
- 20
- 30

Nagarajan B P
- 129
- 2
- 9
-
Have you checked your NSG? https://learn.microsoft.com/en-us/azure/app-service/environment/network-info – Ken W - Zero Networks Oct 29 '18 at 01:17
-
Both are in the same ase and I am able to access the web api using tcpping from kudu console. – Nagarajan B P Oct 29 '18 at 01:53
-
Yes, you could also try my method to call webapi, it works well. – Joey Cai Oct 30 '18 at 01:22
2 Answers
1
I was able to resolve the issue by setting the below in my code.This resolved the Security Error.
using(var handler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (sender,certificate,chain,sslPolicyErrors) => true
})

Tom Sun - MSFT
- 24,161
- 3
- 30
- 47

Nagarajan B P
- 129
- 2
- 9
0
You could create a console app and publish it as Azure WebJobs. For username and password you could click Get Publish Profile
in your Azure webapp overview to get them.
Then you could use the following code in Console App to call your Azure Webapi.
string userName = "$xxxxxx";
string userPassword = "xxxxxxxxxxxxx";
string webAppName = "xxxxxx";
var base64Auth = Convert.ToBase64String(Encoding.Default.GetBytes($"{userName}:{userPassword}"));
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", "Basic " + base64Auth);
var baseUrl = new Uri($"https://{webAppName}.azurewebsites.net/api/values");
var result = client.GetAsync(baseUrl).Result;
if (result.IsSuccessStatusCode)
{
var readTask = result.Content.ReadAsStringAsync();
readTask.Wait();
var value = readTask.Result;
Console.WriteLine(value.ToString());
}
}
Console.WriteLine("run successfully");

Joey Cai
- 18,968
- 1
- 20
- 30