المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Trouble with making multiple httpWebRequest "Get"'s to a webservice in a short time



C# Programming
07-01-2009, 10:42 AM
I have the following code set up to iterate through an array making an http get request on each loop. The trouble I am having is that after about the 9th queue I start to get 503 : Errors from the server. Am I doing something wrong? This currently runs on a timer than runs every 5 seconds. I did alot of reading on this over the last couple days and it appears that I am properly reusing the objects, doing a netstat -an from my machine shows only one connection to the server, but I am essentially doing 17 http Gets every 5 seconds.


foreach (Queue queue in Queues)
{
try
{

string uri = "myProvider/com.broadsoft.xsi-actions/v1.0/user/" + queue.Number + "/queue";
XmlDocument xmlDoc = new XmlDocument();
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);
webRequest.Credentials = new NetworkCredential("MyUser", "MyPass");

webRequest.Timeout = 5000;
webRequest.UserAgent = ".NET Framework Test Client";

HttpWebResponse wResponse = (HttpWebResponse)webRequest.GetResponse();

using (StreamReader responseStream = new StreamReader(wResponse.GetResponseStream()))
{

xmlDoc.Load(responseStream);
StringBuilder aHttpCallXmlOutL = new StringBuilder();
string tempString;
while ((tempString = responseStream.ReadLine()) != null) { aHttpCallXmlOutL.Append(tempString + "\r\n"); }
responseStream.Close();
wResponse.Close();
}