TimeOut HttpWebRequest Second time

1
public static bool Sinc(int v, out List<Ma> x)
        {
            try
            {


                XmlDocument urlData = new XmlDocument();
                HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://192.168.1.155/Ser.svc/maq/?v=" + v;

                rq.Timeout = 30000;

                HttpWebResponse response = rq.GetResponse() as HttpWebResponse;



                using (Stream responseStream = response.GetResponseStream())
                {
                    XmlTextReader reader = new XmlTextReader(responseStream);
                    urlData.Load(reader);
                }

                XmlNodeList companyList = urlData.GetElementsByTagName("VP");
                List<Ma> z = new List<Ma>();
                foreach (XmlNode node in companyList)
                {
                   ......
                }


                if (z.Count != 0)
                {
                    x = z;
                    return true;
                }
                else
                {
                    x = z;
                    return false;
                }
            }
            catch
            {
                x = null;
                return false;
            }
        }

I use this function to get data from my WEBSERVICE , when I use it the first time it works without any problems. When I use it the second time it gives me error of timeout , I leave the application and enter and return to work correctly. Anyone know what it might be?

    
asked by anonymous 19.05.2014 / 14:29

1 answer

1

Try to use your GetResponse within a block usign

something like this:

using (WebResponse response = rq.GetResponse())
{
    using (Stream responseStream = response.GetResponseStream())
    {
        XmlTextReader reader = new XmlTextReader(responseStream);
        urlData.Load(reader);
    }
    //... o que mais for fazer utilizando ainda o response
}
    
19.05.2014 / 14:54