1

The inner exception: System.Net.Sockets.SocketException (0x80004005): 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

Background: This error comes from a webservice being called. When Visual Studio is run locally it works without a hitch. When I deploy this application out to a server, hitting the same webservice, I get this error.

What I have tried: Creating the URI from c# library rather than a using a string. Nulling out the proxy property of my WebClient object. Adding an entry in my web.config file for bypass some proxy stuff.

Relevant code:

            try
            {
                var uri = ConfigurationManager.AppSettings["MyUrl"] + "apiAction";
                using (var httpClient = new WebClient())
                {
                    httpClient.BaseAddress = uri;

                    httpClient.Headers.Add("content-type", "application/json; charset=utf-8");
                    var content = new
                    {
                        UserAuthorizationToken = userToken
                    };
                    var jsonObj = JsonConvert.SerializeObject(content);

                    var response = httpClient.UploadString(uri, jsonObj);

                }
            }

Could anyone point me in the right direction to figuring this out? Thanks in advance

Edit (to prevent having to dig in comments):

The URL is verified to be correct. There are angular functions that are successfully accessing this same method in other places in the application. So, I think that there shouldn't be a firewall issue but I am sort of lost at the moment so I cannot confidently say that there isn't. I can also remote into this server

TopBanana9000
  • 818
  • 2
  • 14
  • 32
  • 1
    Did you make sure the correct settings are in production? Do you log the URL it tries to access? Did you try remoting into the machine and verifying you can reach the URL in the browser? Did you verify that the machine isn't being blocked by firewalls? – mason Dec 15 '17 at 19:46
  • The URL is verified to be correct. There are angular functions that are successfully accessing this same method in other places in the application. So, I think that there shouldn't be a firewall issue but I am sort of lost at the moment so I cannot confidently say that there isn't. I can also remote into this server – TopBanana9000 Dec 15 '17 at 19:49
  • 1
    Are you saying when the API is accessing from the client side (javascript code) it works fine, but when called from the server it doesn't? If you're 100% sure the URL is right, then it's surely a network/firewall issue. RDP'ing into the server and ensuring you can access it with a browser or powershell Invoke-WebRequest is definitely worth trying. – Dylan Nicholson Dec 15 '17 at 20:37
  • Are you saying when the API is accessing from the client side (javascript code) it works fine, but when called from the server it doesn't? <-- This is correct. It also will run fine from my Visual Studio instance. I know the url is right because I am displaying the URL in the UI that is called. I will give your suggestion a shot. Thank you – TopBanana9000 Dec 15 '17 at 20:49

1 Answers1

1

The answer for this turned out to be a firewall issue as Mason and Dylan Nicholson pointed out. I appreciate the direction, folks.

TopBanana9000
  • 818
  • 2
  • 14
  • 32