Problem with WebProxy class

  • Thread starter Thread starter Clinton Forbes
  • Start date Start date
C

Clinton Forbes

I recently encountered a problem with the following piece of code in
an ASP.NET application that has been running successfully for a couple
of months. It requests a web-page from an external web-site, using
our corporate proxy.

Our company has two proxy servers with the same DNS name. If you
execute the nslookup command (at the Windows command prompt), two IP
addresses are returned. When one of the proxy server crashes (as it
did the other day), Internet Explorer continues to work correctly.
However my code failed until the dead proxy server was fixed. It
seemed to cache the IP address of the failed proxy server and continue
to try and use that machine rather than switching to the live machine.

Is there anything I can do to stop this behaviour?

Here is the code:

HttpWebRequest hwrRequest = (HttpWebRequest)WebRequest.Create(
IntranetConfiguration.ExternalSystemConnectionStrings[sExternalSystemKey]);

hwrRequest.Timeout = REQUEST_TIMEOUT;

//Set up proxy information
hwrRequest.Proxy = new WebProxy(
IntranetConfiguration.Proxy.Address,
IntranetConfiguration.Proxy.Port);
hwrRequest.Proxy.Credentials = new NetworkCredential(
IntranetConfiguration.Proxy.Username,
IntranetConfiguration.Proxy.Password);

//Go and get text response from Shareprice service
HttpWebResponse hwrResponse =
(HttpWebResponse)hwrRequest.GetResponse();

Stream strResponse = hwrResponse.GetResponseStream();
StreamReader srResponse = new StreamReader(strResponse);
sHtmlText = srResponse.ReadToEnd();
 
Clinton said:
I recently encountered a problem with the following piece of code in
an ASP.NET application that has been running successfully for a couple
of months. It requests a web-page from an external web-site, using
our corporate proxy.

Our company has two proxy servers with the same DNS name. If you
execute the nslookup command (at the Windows command prompt), two IP
addresses are returned. When one of the proxy server crashes (as it
did the other day), Internet Explorer continues to work correctly.
However my code failed until the dead proxy server was fixed. It
seemed to cache the IP address of the failed proxy server and continue
to try and use that machine rather than switching to the live machine.

Is there anything I can do to stop this behaviour?

[...]

One approach would be to query ypur DNS server for all IP adresses of your
proxy server, use those IP addresses instead of names, and implement a
failover mechanism using a rather aggressive timeout.

Cheers,
 
Back
Top