We have a service which runs at one hour and checks if configured URI's are working (UP) or not. We have around 10 URI's to check.
Strangely for for one particular URI which is giving intermittent error:
Error Message : The underlying connection was closed: Unable to connect to the remote server.
Error Source : System
Error Exception : System.Net.WebException: The underlying connection was closed: Unable to connect to the remote server.
at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.HttpWebRequest.GetResponse()
Generally this error we get when we the destination website is down. But thats not the case the website is fully functional.
Here is my code:
StreamReader objSR =
null;HttpWebRequest objRequest =
null;HttpWebResponse objResponse =
null;try
{
objRequest = (HttpWebRequest) HttpWebRequest.Create(ser.ServiceInfo.Name.ToString());
objResponse = (HttpWebResponse) objRequest.GetResponse();
objSR = new StreamReader(objResponse.GetResponseStream(), System.Text.Encoding.ASCII);
System.Text.StringBuilder sb =
new System.Text.StringBuilder();Pls let us know if there is something wrong..or any alternate solution!!!!

Intresting: Intermittent error With HTTPWebRequest
chiquiman
Check the machine using the IP address, not the URI to verify it is working. It is possible that the machine name resolves to a wrong IP address and goes to another machine
For example if you have a url like that:
http://yourmachinename/path/file go to
http://correctip/path/file
Mariya
NumberKruncher
Thanks Mariya..
Well It that is the case then should it not happen every time...The error I gave happens only 15% of the total hits.
Also, if I type the URI in the browser then page comes up fine.
Any thoughts..
Regards..
dvdribeiro
I have seen a similar behavior when one of our servers changed its IP address and some of the DNS servers would still have the old entry - so sometimes it resolved to its correct IP and the request succeeded, sometimes it resolved to the old ip and the request failed.
That being said, your case may be different. To determine the exact cause you'll need to trace your request to see what goes on the wire. You can either get a System.Net trace or a Netmon trace. Here are instructions how to do this:
http://blogs.msdn.com/dgorti/archive/2005/09/18/471003.aspx
http://blogs.msdn.com/dgorti/archive/2005/10/29/486887.aspx
Mariya