1
votes

I have two web API apps (App Service resources) in Azure: app1 and app2. I'm trying to send https requests from app1 to app2 but connections fail with this error:

"An error occurred while sending the request. Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host"

When I run app1 on my local dev machine (e.g. from VS 2017) I can connect to app2 in Azure with no problems.

I use the following code to POST a request from app1 to app2:

using (HttpClient client = new HttpClient())
{
    HttpResponseMessage response = await client.PostAsync(uri, stringContent);
}
3
Does this happen intermittently or all the time? Has it ever worked? - Mehdi Ibrahim
What is the value of uri? - juunas
@MehdiIbrahim It happens all the time. It never worked. - bdristan
@juunas: I cannot disclose the full uri at the moment. Example of a uri format: https://<subdomain>.azurewebsites.net/api/aux/seed. The same uri works fine from my dev machine which is not in Azure. - bdristan
Yeah, I just wanted to know you are actually calling the proper URL and not localhost or something :) - juunas

3 Answers

0
votes
  1. Is StringContent huge?
  2. Or is the API you are consuming doing any processing that is tanking your resources?
  3. Are there multiple concurrent requests - e.g. are you calling the API asynchronously or with multiple threads in a loop?

The error indicates that a connection is successful but there's something wrong with the API. In my past experience, I've run into this problem when the API's host was running low on memory and high on CPU. Some of the items above could cause this.

Try invoking the API with an empty string parameter.

0
votes

I had the same situation (App Service A calling App Service B) and finally found the problem.

In SSL Settings of App Service B, I had to lower Minimum TLS Version to 1.0.

Of course it would be better to make App Service A use a higher TLS version, but I am unsure how to set this.

0
votes

It turns out you cannot use the default address for the service. It uses azuresites.net SSL cert which I could not get to work. As soon as I created my own url and ssl cert, it worked fine.