Below code is a simple ASP.NET website hosted on IIS. When I run the website from local machine it works fine for both environmentName (UAT and SYSTEM). But when hosted on IIS, I get error while calling WebApi for SYSTEM environment and UAT works fine.
string uri = string.Empty;
StringBuilder sbResult = new StringBuilder();
string message = string.Empty;
try
{
using (HttpClient client = new HttpClient())
{
if (environmentName.ToLower().Contains("system"))
uri = "http://172.26.25.53:5453/"; // SYS
else
uri = "http://172.26.129.21:5453/"; // UAT
client.BaseAddress = new Uri(uri);
var response = client.GetAsync("api/AppFabric").Result;
if (response.IsSuccessStatusCode)
{
}
}
}
When I run this code for environmentName "UAT", it runs fine. But when environment name is "SYSTEM" I get exception as below
System.AggregateException: One or more errors occurred. ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: 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 172.26.25.53:5453 at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
Please help, I am new to WebApi. Is there I am missing something. I have hosted WebApi on both environments in same way.
InnerExceptionfromHttpRequestExceptionwhich you get. It can provide you more detailed information.