Reputation: 349
I have a Windows 8.1 application running on a Windows 10 Enterprise tablet. This app is calling an ASP.NET RESTful Web API running on a remote server. The Web API is using Windows Authentication. I have Fiddler installed on the tablet and I can make calls into the Web API so that proves the Web API is available to the outside world.
Here is the code I use to make the call:
if (WebApiAuthClientHandler == null)
{
WebApiAuthClientHandler = new HttpClientHandler()
{
Credentials = CredentialCache.DefaultNetworkCredentials,
ClientCertificateOptions = ClientCertificateOption.Automatic
};
}
if (WebApiHttpClient == null)
{
WebApiHttpClient = new HttpClient(WebApiAuthClientHandler)
{
BaseAddress = new Uri(_serviceUri, UriKind.Absolute),
Timeout = new TimeSpan(0, 0, 150)
};
WebApiHttpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
}
HttpResponseMessage response = await WebApiHttpClient.GetAsync("api/user", HttpCompletionOption.ResponseContentRead).ConfigureAwait(continueOnCapturedContext: false);
var userLoginInfo = await response.Content.ReadAsAsync<UserLoginInformation>();
where WebApiAuthClientHandler and WebApiHttpClient are my class' static members.
The _serviceUri is constructed from the app's settings and results in a nicely formatted absolute URI like "http://10.120.4.0:5000". Like I said, if I issue a GET HTTP command with Fiddler to the URL "http://10.120.4.0:5000/api/user" I get the expected response on my tablet.
The problem is that my GetAsync call throws an exception after about 21 seconds. It is not timeout, because, as you can see, I set the timeout to 150 seconds (I know it's too much, but for now I was just trying to eliminate all potential causes). The exception thrown is of type HttpRequestException and the several nested messages inform me that I was "Unable to connect to the remote server" because "A Connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 127.0.0.1:8888"
This last part really puzzles me because I do not try to access the Web API locally but remotely, having passed the proper remote URL address.
This issue it's been bugging me for close to two weeks and I still have no resolution to it. Any suggestion would be highly appreciated.
TIA, Eddie
Upvotes: 0
Views: 2148