3

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.

6
  • 1
    is there any firewall blocking sites for restricted access? that can affect your response. Commented Jul 6, 2015 at 7:01
  • Try to check InnerException from HttpRequestException which you get. It can provide you more detailed information. Commented Jul 6, 2015 at 7:05
  • But I am able to run the code from local machine Visual Studio, but when I host it on IIS of other server (but same domain as WebAPI servers) then I get exception. I also ran the WebApi for SYSTEM environment on hosted server and it works fine. So, if firewall is an issue on which server I should see, hosted IIS server or WebApi server. Sorry for being naïve but I have just started with all this. Thanks for response. Commented Jul 6, 2015 at 7:11
  • Is port 5453 assigned by visual studio? IIS normally runs on port 80. Can you try accessing using "172.26.25.53"? Commented Jul 6, 2015 at 7:14
  • no the port was assigned by me in IIS as port 80 was taken up by other website. Commented Jul 6, 2015 at 10:04

1 Answer 1

2

I found this was a timeout problem. To fix this I increased the connection time in IIS. In IIS I went to the default website, right clicked --> Manage Website --> Advanced Settings --> Connection Limits (expand) --> change the default from 120 to (say) 180.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.