I am developing an au Universal application using MVVM-Light .
The page has a list of comments coming from WebService. If the current user is the author of the comment, I display FlyoutMenu, letting him “Edit” or “Delete” my comment. There is also an AppBarButton for adding a new comment:

My problem is that comments are never updated after the first load of this page ...
I use the LoadComments () method in ViewModel , which allows me to get comments when I come to the page, but also after editing, deleting or adding an element:
private async void LoadComments()
{
List<Comment> commentsWS = await WebServiceGetCommentList();
if (commentsWS != null)
Comments = new ObservableCollection<Commentaire>(commentsWS);
}
This method calls another method, " WebServiceGetCommentList () ", which prepares a call to the WebService in the same ViewModel :
private async Task<List<Comment>> WebServiceGetCommentList()
{
List<KeyValuePair<string, string>> parametres = new List<KeyValuePair<string, string>>();
parametres.Add(new KeyValuePair<string, string>("option", _currentUserAccount.option));
parametres.Add(new KeyValuePair<string, string>("id_article", Article.id_article.ToString()));
Exception custEx = null;
try
{
List<Comment> comments = await WebServices.GetCommentList(_currentUserAccount.url, parametres, "");
return comments;
}
catch (Exception e)
{
...
}
return null;
}
Then I go to the GetComments () method in the WebServices class :
public static async Task<List<Comment>> GetCommentList(String url, List<KeyValuePair<String, String>> parametres, String protocol)
{
var response = await JSONParser.getJSONFromUrl(url, parametres, "");
List<Comment> comments = new List<Comment>();
WsResponse wsResponse = ManageWsReponse(response, Constants.WebServiceTask.GetCommentList.Value);
try
{
WsResponseResult wsResponseResult = JsonConvert.DeserializeObject<WsResponseResult>(wsResponse.data.ToString());
comments = JsonConvert.DeserializeObject<List<Comment>>(wsResponseResult.result.ToString());
return comments;
}
catch (Exception e)
{
throw new DeserializeException("Deserialize exception", e, DateTime.Now, "Comment");
}
}
This method calls the getJSONFromUrl () method in the JSONParser class , which runs " client.GetAsync ()
public static async Task<string> getJSONFromUrl(String url, List<KeyValuePair<String, String>> parameters, String protocol)
{
var client = new HttpClient();
string sParameters = null;
int i = 1;
foreach (var param in parameters)
{
sParameters += param.Key + "=" + param.Value;
sParameters += i != parameters.Count ? "&" : string.Empty;
i++;
}
var uri = new Uri(url + "?" + sParameters);
var response = await client.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead);
var statusCode = response.StatusCode;
response.EnsureSuccessStatusCode();
var responseText = await response.Content.ReadAsStringAsync();
return responseText;
}
I can add, delete, or edit the comment with success, but when I return to this " LoadComments () " method , the changes are not taken into account, and I get the same thing as when I first called ...
GetJSONFromURL(), , var.
, URI , WebService .
= > , client.GetAsync(), , , ...
httpclient-caching, .
, ,