HttpWebRequest - Is there anyway to clear IP Address cached in ServicePoint?



Anyone know is there any workaround or is there anyway I can clear the
IP address cached by the Service Point?
I have a C# service that keep submitting to a server using a
HTTPWebrequest. The problem is when the remote server fail-over,
HTTPWebRequest still trying to submit to the old server/IPAddress. It
looks like the ServicePoint cache the IP Address internally by the
After fail-over, the hostname is still remain the same but the IP has
changed. Is there anyway I can clear the cache? BTW, I can't submit
using the IP Address because there is SSL that tie with the hostname.

The following is the snippet to reproduce the problem.

1. Create a Windows App. add a button and a textbox with multiline

2. Add the following code into the button onclick event
HttpWebRequest objHttpWebRequest =
objHttpWebRequest.Method = "GET";
objHttpWebRequest.Timeout = 5000;
WebResponse objResponse = objHttpWebRequest.GetResponse();
StreamReader objStreamReader = new
textBox1.Text = objStreamReader.ReadToEnd();

3. Click on the button once and you will see google's HTML code in the

4. To Reproduce the failover, go to your local hosts file
(C:\WINNT\system32\drivers\etc\hosts) and add the following entry so
the traffic will go to website while the program still
hitting the google url.

5. Click the button again and pay attention that the code is still
referencing to google website. But once you close the app. and open
again, then it will see the dell website.

I tried using the ConnectionGroupName, ServicePoint.MaxIdleTime
nothing is working.
I can make it to work in debug by manipulating the local variable
value in Service point:
m_CurrentAddressInfoIndex = m_IPHostEntryInfo.IPAddressInfoList.Length
m_ConnectionsSinceDns = -1

Since ServicePoint is an internal class there is no way I can override
it. Any recommendation will be appreciated.



Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question