×

Discussion Board

Results 1 to 12 of 12
  1. #1
    Registered User
    Join Date
    Jun 2014
    Posts
    5

    Problem to download a string of 3800 characters - HttpClient Windows Phone 7

    Good morning everyone, I have a problem when trying to download the Content of a service that has 3800 characters, the following error occurs:

    System.Exception: Error HRESULT E_FAIL has-been returned from a call to a COM component.
    at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse (IAsyncResult asyncResult)
    at System.Net.Browser.ClientHttpWebRequest. <> c__DisplayClasse. <EndGetResponse> b__d (Object sendState)
    at System.Net.Browser.AsyncHelper. <> c__DisplayClass1. <BeginOnUI> b__0 (Object sendState)
    --- End of inner exception stack trace ---
    at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (Task task)
    at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess (Task task)
    at Microsoft.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (Task task)
    1.GetResult at Microsoft.Runtime.CompilerServices.TaskAwaiter `()
    at MyApp.ConnectionHelper. <postActivationCode> d__0.MoveNext ()}

    I tried to modify the MaxResponseContentBufferSize parameter HttpClient with methods PostAsync or GetAsync and has not worked, I changed the type of connection (HtttpClient, HttpWebRequest and WebClient) and occurred same exception, also I have tried to make synchronous process but does not work and the debugger stops the process by the time delay. This exception occurs when trying to read the contents of the response in different formats byte [] and string stream. So my question is why occurred this exception, or I can implement another method to download this response without problems to the size large of the answer. Thank you very much to all.

  2. #2
    Regular Contributor
    Join Date
    Aug 2012
    Location
    Rhine Valley
    Posts
    93

    Re: Problem to download a string of 3800 characters - HttpClient Windows Phone 7

    Can you show us a bit of code?
    I suspect the size is not the reason for the problem...
    - <a href="http://www.dvlup.com/influencer/invite">Visit DVLUP and earn rewards</a>

  3. #3
    Super Contributor
    Join Date
    Feb 2013
    Location
    Dublin, Ireland
    Posts
    580

    Re: Problem to download a string of 3800 characters - HttpClient Windows Phone 7

    Also, just curious, but is this a new app?

  4. #4
    Registered User
    Join Date
    Jun 2014
    Posts
    5

    Re: Problem to download a string of 3800 characters - HttpClient Windows Phone 7

    First thank you very much for your prompt replies, this is the code that implements for web requests by HttpClient:

    public async Task<string> webRequest(string url, string dataToSend)
    {
    string response = null;
    Uri uriweb = new Uri(url);
    HttpClient httpClient = new HttpClient();
    httpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("MyApp", "1.1"));
    httpClient.MaxResponseContentBufferSize = 2147483647L;
    httpClient.Timeout = new TimeSpan(0, 0, 2);

    try
    {

    HttpResponseMessage test = new HttpResponseMessage();
    if (dataToSend != null)
    {
    HttpContent sendPostData = new StringContent(dataToSend);

    test= await httpClient.PostAsync(uriweb, sendPostData);
    }
    else
    {
    test = await httpClient.GetAsync(uriweb, HttpCompletionOption.ResponseHeadersRead);
    }
    test.EnsureSuccessStatusCode();
    response = await test.Content.ReadAsStringAsync();
    }
    catch (Exception e)
    {
    e.InnerException.ToString();
    Console.Write(e.Message);

    }
    return response;
    }
    Last edited by DanielEAyalaR; 2014-06-12 at 19:24.

  5. #5
    Super Contributor
    Join Date
    Feb 2013
    Location
    Dublin, Ireland
    Posts
    580

    Re: Problem to download a string of 3800 characters - HttpClient Windows Phone 7

    Try removing...

    httpClient.MaxResponseContentBufferSize = 2147483647L;
    httpClient.Timeout = new TimeSpan(0, 0, 2);

    (A 2 second timeout is too short, 10 - 30 seconds is more reasonable)

  6. #6
    Registered User
    Join Date
    Jun 2014
    Posts
    5

    Re: Problem to download a string of 3800 characters - HttpClient Windows Phone 7

    I removed this lines and get the same exception then I changed Timeout to 60 seconds and I have the same result, I think that the problem its the large size string of Server Response because the last line of Exception said: at MyApp.ConnectionHelper. <webRequest> d__0.MoveNext ()

  7. #7
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    526

    Re: Problem to download a string of 3800 characters - HttpClient Windows Phone 7

    MoveNext() is only a reference to the part of an async method that the error occured in as async is separating a method into several upon compilation. This likely is not related to moving to the next character.

  8. #8
    Registered User
    Join Date
    Jun 2014
    Posts
    5

    Re: Problem to download a string of 3800 characters - HttpClient Windows Phone 7

    Thanks for the clarification but I don't understand why this exception occurs, the same method works for shorter answers but with the size of the string not allow me to read it in a variable of type HttpResponseMessage
    Last edited by DanielEAyalaR; 2014-06-12 at 20:48.

  9. #9
    Registered User
    Join Date
    Mar 2013
    Posts
    13

    -

    Without a timeout, your code worked perfectly for me. This downloaded a string of 113253 characters:
    Code:
        webRequest("http://microsoft.com", null);
    Can you share the URL that is causing your problem?

    .
    Last edited by Metro Developer; 2014-06-15 at 19:26.

  10. #10
    Registered User
    Join Date
    Sep 2012
    Posts
    1

    Re: Problem to download a string of 3800 characters - HttpClient Windows Phone 7

    Real answer is that task implementation for HttpClient is buggy, just avoid using it.

  11. #11
    Super Contributor
    Join Date
    Feb 2013
    Location
    Dublin, Ireland
    Posts
    580

    Re: Problem to download a string of 3800 characters - HttpClient Windows Phone 7

    Quote Originally Posted by jinek View Post
    Real answer is that task implementation for HttpClient is buggy, just avoid using it.
    What bugs have you run into, and are they WP7 only?

  12. #12
    Registered User
    Join Date
    Jun 2014
    Posts
    5

    Re: Problem to download a string of 3800 characters - HttpClient Windows Phone 7

    Thanks for your replies, I have created new services in ASP.NET MVC with same response and it works perfect, but the first web services (in PHP) works in other platforms (iOS-Android) this problem it occurs in WP7 and WP8, now I will working with my new services meanwhile. But in what scenarios occur this problem?, for review PHP services, thanks for your help.

Similar Threads

  1. Replies: 4
    Last Post: 2013-07-29, 20:12
  2. dial a string (with pause characters) in FP2
    By noam.segal in forum Symbian
    Replies: 3
    Last Post: 2011-03-14, 17:21
  3. Store string more than 32 characters
    By zhyferox in forum Mobile Java General
    Replies: 2
    Last Post: 2010-08-22, 16:29
  4. Java Tools Download problem on Windows XP SP2
    By saifuaa in forum Mobile Java Tools & SDKs
    Replies: 0
    Last Post: 2005-02-01, 07:17

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×