locked
HttpClient Timeout is not increasing abow 100sec RRS feed

  • Question

  • Hi all,

    I am recently used an HttpClient libraries to extend Timeout for for request. but i am not able to extend the the timeout. Please tell me can we extend the timeout up to 5minates. Here is my sample code:

    using (var httpClient = new HttpClient())
                {
                    httpClient.Timeout = new TimeSpan(0, 0, 0, 0, 300000);
                    var response = await httpClient.PostAsync(uri, new StringContent(data));
                    response.EnsureSuccessStatusCode();
                    string content = await response.Content.ReadAsStringAsync();
                    return content;
                }

    thanks in advance.


    Pallam Madhukar Windows Phone Developer

    Monday, December 9, 2013 8:13 AM

All replies

  • Your issue is looking more similar to the issue posted at http://stackoverflow.com/questions/7842736/cant-set-httpwebrequest-timeout-higher-than-100-seconds-when-doing-a-post?rq=1

    Please check the answer in that post.

    Monday, December 9, 2013 8:48 AM
  • Hi Seetha.

    thanks for reply, I gone through that link but i am not able to figure out, where i need to set the timeout. Please can you give sample code, so that i can easily understood.

    Thanks.


    Pallam Madhukar Windows Phone Developer

    Monday, December 9, 2013 1:13 PM
  • Hi all,

    Please tell me can we increase time for http request. i getting exception after 100sec. I have tried HttpWebRequest and HttpClient. In HttpWebRequest there is no direct way to give timeout. In HttpClient we have Timeout property, but even i mentioned the timeout property, the request returned after 100sec only. i want to set timeout for 5minates. Please tell me any possible solutions. i searched many times but could not found any results. Please tell me solution. 

    Thanks in advance.


    Pallam Madhukar Windows Phone Developer

    Monday, December 9, 2013 1:55 PM
  • Please give me solution or any suggestions.

    Pallam Madhukar Windows Phone Developer

    Monday, December 9, 2013 7:36 PM
  • Pallam Madhukar,

    If you have only one call like what you have posted here, then the code is fine. I assume the method is marked as async and called with await.

    But 5 minutes is too long for any service request. And timeout is not just managed by client, but also by the service. Please check your service for the maxrequesttimeout. Most of the services will have the timeout in seconds. If nothing specified in the service, please look for the service configuration to set the timeout option for the request.

    Once you increase that the communication timeout will get increased.

    Tuesday, December 10, 2013 4:08 AM
  • thanks Seetha_

    i will look into service code and i will confirm you.

    i am using only one service which takes 2min 30 sec. Can you confirm that the above code will work? Because In android & iPhone they are hitting same service and they able to wait for 2min 30sec. Please put me in right way to solve this issue.

    thanks.


    Pallam Madhukar Windows Phone Developer

    Tuesday, December 10, 2013 5:31 AM
  • If you can hit the same service with TimeOut of around 3 mins from Android, then the Service should be good for Timeout. And the above code should work good for that...

    One more stuff you can try is that... using some RestClient. You can use SoapUI or you can even use RestClient plugin for Chrome to verify this. This way, you can clearly find out whether is it because of client or something else is happening.

    Tuesday, December 10, 2013 9:22 AM
  • Hi Seetha_

    I am not figured out the mistake. Where the plugin in mozilla working fine with the service.

    Mozilla plugin: https://addons.mozilla.org/en-US/firefox/addon/restclient/

    I have tried RestClient Library from Nuget: http://www.nuget.org/packages/RestSharp

    Here is my sample code:

    private void GetData(string baseUrl)
            {
                var client = new RestClient();
                var request = new RestRequest(baseUrl, Method.GET);
                client.Timeout = 3 * 60 * 1000;
                request.Timeout = 3 * 60 * 1000;
                client.GetAsync(request, Callback);
            }
            private void Callback(IRestResponse response, RestRequestAsyncHandle arg2)
            {
                try
                {
                    var content = response.Content; // raw content as string
                }
                catch { }
            }

    The Callback method is fired after 60sec. Please can you help?

    thanks.



    Pallam Madhukar Windows Phone Developer

    Tuesday, December 10, 2013 12:17 PM
  • Pallam Madhukar, Whether your service is accessible over internet? If so, are you ok to share the details to me? I can try it out and see if I can help anything.
    Tuesday, December 10, 2013 4:38 PM
  • Sorry Seetha_

    as it is not public, i can't provide the url. If possible please can you provide sample code in which request will wait for 3minates. That will help me.

    thanks.


    Pallam Madhukar Windows Phone Developer

    Wednesday, December 11, 2013 7:17 AM
  • Is there a solution to this problem? I run into the same issue. It's not possible to set timeout greater than 100 seconds.
    Friday, October 24, 2014 1:32 PM