Reputation: 35
I have a windows phone app that connects to a local IIS Server. It downloads some json data and displays it in a list box. I also have a refresh button on the page. When the page loads everything is correct but pressing the refresh button only returns the same data that was available when the page is loaded. I have checked my web browser with the uri and the updated data shows there correctly. Also If I exit the windows phone app and reload it the data is there. Here is some dumbed down code I am testing with.
On page load:
WebClient download = new WebClient();
download.DownloadStringCompleted += new DownloadStringCompletedEventHandler(download_DownloadStringCompleted);
download.DownloadStringAsync(new Uri("http://sampledata/data"));
void download_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
MessageBox.Show(e.Result);
}
This works fine and displays a message box with my json string.
On Refresh:
private void Button_Click(object sender, RoutedEventArgs e)
{
WebClient refresh = new WebClient();
refresh.DownloadStringCompleted += new DownloadStringCompletedEventHandler(refresh_DownloadStringCompleted);
refresh.DownloadStringAsync(new Uri("http://sampledata/data"));
}
void refresh_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
MessageBox.Show(e.Result);
}
This displays the same json string that was displayed on page load even though the data has changed. Does anyone have any ideas? Thanks.
Upvotes: 0
Views: 643
Reputation: 11
try adding a time stamp to the end of the URL. like refresh.DownloadStringAsync(new URI("http://sampledata/data" + DateTime.Now.ToString()));
Upvotes: 1
Reputation: 464
How much data do You pulling out from server? Try with HttpWebRequest if you need heavy lifting. I also had some issuses with webclient loading and refreshing data. Every change on server comes with big delay...
Upvotes: 0