HttpClient GetAsync not working properly in WP8.1 but working fine in other application RRS feed

  • Question

  • Hello,

    In my wp8.1 (RT) app i have to load message from server. So when i first logged into app then it will return all new messages but after that it only returns the data that it previously returned even though new message is arrived in server but same code works fine in WPF application. What could be the problem in wp8.1?

    My code look like this.

    while (NetworkInterface.GetIsNetworkAvailable())
    var response = await client.GetAsync(new Uri("api to get message"));
             if (response.StatusCode ==System.Net.HttpStatusCode.OK)
                        var data = await response.Content.ReadAsStringAsync();
                        using (var stream = new MemoryStream(Encoding.Unicode.GetBytes(data)))
                            var serializer = new DataContractJsonSerializer(typeof(List<RecievedMsg>));
                            Received_Msg = (List<RecievedMsg>)serializer.ReadObject(stream);
    In wp8.1 Received_Msg only contains old message even if new message is there in server. What else i found is that client.getasync() method is not called correctly i.e the request is not reached up to server (i checked with local host) but also it shows 200 OK with old data. Did i made any mistake in my code? And why it worked with WPF but not with WP8.1?


    • Edited by Janaks Wednesday, September 2, 2015 4:59 PM
    Wednesday, September 2, 2015 4:56 PM


  • Not really enough here to help.

    What is the get client exactly (what type of class / object is it)

    You say that you are only getting the old data (sounds like a proxy / caching issue to me).

    You said it's not called properly... how do you know for sure? Since I don't know what type of client you are using, I can't really easily tell you other than to assume it's some HTTPClient or something else?

    Since you are getting data back either

    1) it's a caching problem on the protocol / client you are using

    2) you aren't actually clearing out the memory of the actual (previous) "buffer" because I can see above you are not initializes the buffers in this actual loop

    3) there is just too much missing to really help :-) and my guessing sucks.

    Since you said a 200, I assume a web call. Therefor HTTPClient, WebRequest, etc etc

    These things won't give you data that doesn't exist. So that "instance" of the client clearly things you had / have data. And if you didn't close it, dispose of it and clean it out, then you might be just getting old cached data.

    When you step through the code, exactly what happens in your get method. What is the configuration of your client? Do you have "cache" enabled on whatever page / thing it's calling?

    Wednesday, September 2, 2015 8:24 PM