I am having problems with some simple testing code that does bulk downloads from one of our restful services. It appears that the low level socket is not being released by the call to Dispose. Here is the basic code;
foreach(...)
{
using(WebClient client = new WebClient())
{
string results = client.DownloadString("http://host/request");
client.Dispose();
}
}
This causes an exception after 255 loops. I tried adding this line (via some suggestions form another stackoverflow post).
System.Net.ServicePointManager.DefaultConnectionLimit = 500;
Then I get an exception after 500 loops. So, it seems to me the low level socket connection is not being released.
Has anyone else seen this issue? Do you know a work around.
Thanks