Question

I am trying to work with a 3rd party service api . One of the methods they have brings in all records which takes a lot of time , about 9 mins ( i tried this using chrome app "Advanced Rest Client").

I have tried setting the webRequest.Timeout = 3600000;// Timeout.Infinite; But it always comes back after maybe 2 minutes and the result contains 135 records (whereas the chrome app gets back 1050 records, which is correct #)

I am using the same parameters in both cases (i send it as POST data); so why is there difference in the results ? I am using this code in a class library which will be used in a WPF application.

  1. Is there a max value for timeout ?
  2. Timeout.Infinite is setting it to '-1' , is this right ?
  3. What are the other workarounds to get all data ?

Any help/suggestion is greatly appreciated.

Update: Adding code

 HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(url);
       AllDevicesList devInfo = null;
       try
       {
           string postData = "";

           foreach (string key in postParameters.Keys)
           {

               postData += HttpUtility.UrlEncode(key) + "="
                     + HttpUtility.UrlEncode(postParameters[key]) + "&";
           }
           postData = postData.TrimEnd('&');
           if (cookie == null)
               webRequest.CookieContainer = new CookieContainer();
           else
               webRequest.CookieContainer = cookie;


           webRequest.Timeout = 3600000;// Timeout.Infinite; // 1000000;

           webRequest.KeepAlive = true;
           webRequest.Method = "POST";

           byte[] data = Encoding.ASCII.GetBytes(postData);

           webRequest.ContentType = "application/x-www-form-urlencoded";

           webRequest.ContentLength = data.Length;

           Stream requestStream = webRequest.GetRequestStream();
           requestStream.Write(data, 0, data.Length);

           WebResponse WebResp = webRequest.GetResponse();

           DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(AllDevicesList));


           object objResponse = jsonSerializer.ReadObject(WebResp.GetResponseStream());
           devInfo = objResponse as AllDevicesList;


           requestStream.Close();


           WebResp.Close();
Was it helpful?

Solution

I have changed the implementation to Asynchronous and now i get all the records. Thanks for all your responses.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top