0x80004005 A connection attempt failed because the connected party did not properly respond after a period of time


I am facing this problem while accessing web service from ASP.NET application.
But the problem occurs when it is hosted in a windows server.
When it is hosted in desktop it is working fine.
I am calling web service with HttpWebRequest object.

Even it is working fine in server from HTML/Java Script application. Only problem occurs in ASP.NET application hosted in server. I get following error. IIS 8.0 is installed in server.

Unable to connect to the remote server
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 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context) at System.Net.HttpWebRequest.GetRequestStream() at VSPTestApplication.UPS.CalculateRate_Click(Object sender, EventArgs e)
System.IO.Stream GetRequestStream(System.Net.TransportContext ByRef) 
asked on Stack Overflow Dec 19, 2013 by Pabitra Dash • edited Nov 27, 2014 by Rahul Nikate

2 Answers


Looking from your error message I notice that you are trying to hit a HTTPS url. This can be tricky when running in aspnet in IIS, because your code runs in a different user context. And the necessary certificates might not be installed in that context. For eg, if the target server has a certificate signed by a CA that is not trusted by the client's machine (asp.net/iis/windows) then the request wont succeed.

However, a certificate error would manifest clearly. it wouldnt show up as a failure to connect.

I suggest using system.net logging facility to create a logfile. That should help troubleshoot the problem. Also, you should run wireshark on the windows server and see where the server is trying to connect. It might be as simple as that the windows server does not have connectivity to the target. Or there might be a proxy in middle that is screwing up the network path.

To setup system.net logging, you can put the following config file in the same directory as the app that is running your code.

<?xml version="1.0" encoding="UTF-8" ?>

<trace autoflush="true" />

<source name="System.Net">

    <add name="System.Net"/>
<source name="System.Net.Sockets">
    <add name="System.Net"/>
<source name="System.Net.Cache">
    <add name="System.Net"/>
    <add name="System.Net" value="Verbose" />
    <add name="System.Net.Sockets" value="Verbose" />               
    <add name="System.Net.Cache" value="Verbose" />

for more details on logging:

creating a tracelog with system.net

answered on Stack Overflow Feb 27, 2015 by feroze

I also faced the same issue, and got solved just by troubleshooting the network.

in windows-> settings -> Network & Internet -> Network Troubleshooter

answered on Stack Overflow Dec 26, 2018 by (unknown user)

User contributions licensed under CC BY-SA 3.0