locked
An error occurred while sending the request. RRS feed

  • Question

  • When i call  HttpClient service and application go to background  (deactivated) when i go to activate it throw this execption

    {System.Net.WebException: Exception of type 'System.Net.WebException' was thrown. ---> System.Net.WebException: Exception of type 'System.Net.WebException' was thrown.
       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 System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
       at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
       at System.Net.Http.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
       at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)}


    DesertQueen

    Sunday, November 9, 2014 11:43 AM

All replies

  • Hi DevWP,

    >>When i call  HttpClient service and application go to background  (deactivated) when i go to activate it throw execption

    It will be better if you can try to post your code here.

    Then I have created the following WCF Rest Service:

    [ServiceContract]
    public interface IMyService1
    {
    
      [OperationContract]
      [WebGet(UriTemplate = "GetMyData")]
      string GetData();    
    }
    


    After that I can call the above WCF Rest Service with the help of the HttpClient class:

    private async void CallHttpClientService()
    {
        HttpClient httpClient = new HttpClient();
        HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://*******/MyService1.svc/GetMyData");
        HttpResponseMessage response = await httpClient.SendAsync(request);
        string result = await response.Content.ReadAsStringAsync();
        var MessageDialog = new MessageDialog(result );
        await MessageDialog.ShowAsync();
     }

    It just works fine.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by dns jinung Monday, November 10, 2014 8:16 AM
    Monday, November 10, 2014 5:04 AM
  • My app is wp8 application

    DesertQueen

    Monday, November 10, 2014 8:14 AM
  • Try post your full code.
    Monday, November 10, 2014 8:17 AM
  •  public async Task<T> getAds(int type, string url)
            {
                 HttpClient _client = new HttpClient();
               
                _client.DefaultRequestHeaders.Add("Type", type.ToString());
                HttpResponseMessage response = await _client.GetAsync(url + "?id=" + DateTime.Now);
                if ((int)response.StatusCode == 200 || (int)response.StatusCode == 201)
                {
                    var jsonString = await response.Content.ReadAsStringAsync();
                    var lst = JsonConvert.DeserializeObject<T>(jsonString);
                    return lst;
                }
                var o = new object();
                return (T)o;
            }
    • Edited by DevWP Monday, November 10, 2014 8:18 AM update
    Monday, November 10, 2014 8:18 AM
  • I test it in my emulator, works fine. It may cause by your different URI with different content.
    Thursday, November 20, 2014 10:48 AM