WebClient in WP7.1 app is called only once
My problem:
My WebClient is using a function in the cloud (http://127.0.0.1:81/Service1.svc/Data).
But it is not possible to call multiple times (for example, make an update).
Here is my code:
private void button_Click(object sender, RoutedEventArgs e)
{
WebClient cnt = new WebClient();
cnt.DownloadStringCompleted += new DownloadStringCompletedEventHandler(cnt_DownloadStringCompleted);
cnt.DownloadStringAsync(new Uri("http://127.0.0.1:81/Service1.svc/Data"));
}
void cnt_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
int num = JsonHelper.FromJson<int>(e.Result);
textbox.Dispatcher.BeginInvoke(() => textbox.Text = Convert.ToString(num));
}
After every click, the application works fine in cnt_DownloadStringCompleted, but the result (e.Result) never changes after being updated on the server.
On Azure Service, I noticed after a break that the (Data) function is only called once (the first time).
How do I go about calling my service more than once?
source to share
Check the server side to make sure you are not allowing caching. If you have a response context in your service, set:
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Alternatively, if you are unable to do this, post the modified meaninglessness parameter to the querystring, something like:
http://127.0.0.1:81/Service1.svc/Data?nonsense=190AF142-4341-47DC-9CF5-3BC3ACBD02EE
You can generate and submit a new guide every time, or even use it DateTime.Now.Ticks.ToString()
. That being said, if you have control over the server side, remove the caching, as this is a serious hack.
source to share