Reputation: 11304
I have one asp.net web api (app1) which is running with localhost in my machine, https://localhost:44301/weatherforecast
Other asp.net web api (app2) which I hosted over azure app service, https://webapiapp120200626111110.azurewebsites.net/weatherforecast
calling app1's api https://localhost:44301/weatherforecast
[HttpGet]
public async Task<string> Get()
{
var result = string.Empty;
using var client = new HttpClient();
var defaultRequestHeaders = client.DefaultRequestHeaders;
if (defaultRequestHeaders.Accept == null || defaultRequestHeaders.Accept.All(m => m.MediaType != "application/json"))
{
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
}
var response = await client.GetAsync("https://localhost:44301/weatherforecast");
if (response.IsSuccessStatusCode)
{
result = await response.Content.ReadAsStringAsync();
}
return result;
}
Here I am getting 500
error if I host app2
as azure app service, if I run it locally over localhost
, then NO issues.
Is this something block on localhost, how we can do this?
Upvotes: 0
Views: 1119
Reputation: 664
"localhost" refers to the current machine and will in most cases translate to ip4 127.0.0.1. So if your App Sevice "app2" is calling "localhost" it is basically calling itself, not the machine you're hosting "app1" on.
If you want to call "app1" running on your local machine from an Azure App Service then you need to expose "app1" to the internet on your machine.
You'll need to know the public ip your machine is behind, make sure your router etc can route the traffic from the public ip to your machine's internal network ip (There are probably tons of other issues that you're going to run into depending on firewalls, routers, networking infrastructure, if "app1" is running on IIS Express or not, ...).
Just host both "app1" and "app2" on Azure as App Services.
Upvotes: 3