Timeout Httpwebrequest Second time

Asked

Viewed 72 times

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 mine WEBSERVICE, when I use it the first time works without any kind of problem. When I use it the second time gives me error timeout, exits the application and goes back and forth correctly. Does anyone know what might be?

1 answer

1


Try to use your GetResponse within a block usign

something like that:

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
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.