"A connection attempt failed because the connected party did not properly respond after a period of time" using WebClient
I am using the following code which is working on local machine, but when i tried the same code on server it throws me error
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
Here is my code:
WebClient client = new WebClient(); // Add a user agent header in case the // requested URI contains a query. //client.Headers.Add ("ID", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"); Stream data = client.OpenRead("http://" + Request.ServerVariables["HTTP_HOST"] + Request.ApplicationPath + "/PageDetails.aspx?ModuleID=" + ID); StreamReader reader = new StreamReader(data); string s = reader.ReadToEnd(); Console.WriteLine(s); data.Close(); reader.Close();
I am getting error on
Stream data = client.OpenRead("http://" + Request.ServerVariables["HTTP_HOST"] + Request.ApplicationPath + "/PageDetails.aspx?ModuleID=" + ID);
is it due any firewall setting?
I had a similar problem and had to convert the URL from string to Uri object using:
Uri myUri = new Uri(URLInStringFormat, UriKind.Absolute);
(URLInStringFormat is your URL) Try to connect using the Uri instead of the string as:
WebClient client = new WebClient(); client.OpenRead(myUri);
Read more... Read less...
setting the proxy address explicitly in
web.config solved my problem
<system.net> <defaultProxy> <proxy usesystemdefault = "false" proxyaddress="http://address:port" bypassonlocal="false"/> </defaultProxy> </system.net>
I know this ticket is old, but I just ran into this issue and I thought I would post what was happening to me and how I resolved it:
In my service I was calling there was a call to another web service. Like a goof, I forgot to make sure that the DNS settings were correct when I published the web service, thus my web service, when published, was trying to call from api.myproductionserver.local, rather than api.myproductionserver.com. It was the backend web service that was causing the timeout.
Anyways, I thought I would pass this along.
Is the URL that this code is making accessible in the browser?
http://" + Request.ServerVariables["HTTP_HOST"] + Request.ApplicationPath + "/PageDetails.aspx?ModuleID=" + ID
First thing you need to verify is that the URL you are making is correct. Then check in the browser to see if it is browsing. then use Fiddler tool to check what is passing over the network. It may be that URL that is being called through code is wrongly escaped.
Then check for firewall related issues.
First Possibility: The encrypted string in the Related Web.config File should be same as entered in the connection string (which is shown above) And also, when you change anything in the "Registry Editor" or
regedit.exe(as written at Run), then after any change, close the registry editor and reset your Internet Information Services by typing
IISRESETat Run. And then login to your environment.
Type Services.msc on run and check:
Status of ASP.NET State Services is started. If not, then right click on it, through Properties, change its Startup type to automatic.
Iris ReportManager Service of that particular bank is Listed as Started or not. If its Running, It will show "IRIS REPORT MANAGER SERVICE" as started in the list. If not, then run it by clicking
Then Again RESET IIS
I had this problem. Code worked fine when running locally but not when on server. Using psPing (https://technet.microsoft.com/en-us/sysinternals/psping.aspx) I realised the applications port wasn't returning anything. Turned out to be a firewall issue. I hadn't enabled my applications port in the Windows Firewall.
Administrative Tools > Windows Firewall with Advanced Security added my applications port to the Inbound Rules and it started working.
Somehow the application port number had got changed, so took a while to figure out what was going on - so thought I'd share this possibility in case it saves someone else time...