views:

105

answers:

1

Hi All,

I have a WCF service in an ASP.NET AJAX app that is returning json. Im using MS AJAX and the client PageRequesManager to run the service after each endRequest for any partial page updates. The user has a form, they update data and submit and the service needs to grab the latest data. When I debug using FF and FireBug, everything works like a champ. Exactly the way I coded it, however when I run the app in IE, surprise!!! The initial call is current, but subsequent calls were not returning new fresh data. I verfied by adding a record and then doing a ".length" on the JSON object. It should have incremented by 1. I was trying to do some limited debugging using IE Developer Toolbar and Fiddler {which I really don't understand yet}, but I saw a button in the Developer Toolbar to clear the browser cache. I gave it a shot, and kaboom!!! IE starts working as I would expect. I did this one time on my local developer box and it worked, but for how long who knows?? and What can I possibly do for the users of this application? Can I force IE to somehow 'get-latest' if you will? This app of course, is intended to run in IE. Most of the users have likely never even heard of FireFox unfortunately. Has anyone had a similir problem? Any ideas would be appreciated. I didn't post any code as I am not near the source, and basically its ABC plain vanilla javascript. I code similiar to Javascript:The Good Parts by Crockford if thats any indication of quality.

Thanks for any ideas, ~ck in San Diego

+2  A: 

I assume your method is using the WebGetAttribute on your service method? This equates to an HTTP GET verb which will be cached according to browser defaults if no caching headers are specified by the server in the response.

You have two options:

  1. If you're using ASP.NET integrated service hosting (i.e. AspNetCompatibilityAttribute) you can use the HttpRequest::Cache property to set the caching options for the response using the various methods of HttpCachePolicy.
  2. If you're using/want to use "pure" WCF, you can set the ETag and/or LastModified properties of OutgoingWebResponseContext via WebOperationContext::Current::OutgoingResponse. More importantly though you can add the Cache-Control header to the Headers collection.

Here's a great article that contains everything you probably ever need to know about HTTP caching in case you need it.

Drew Marsh
Here I was about to post a flippant response and site unseen code quality and you go and give the guy a real answer.. ;) +1
Chris Lively
All correct Drew. I will read all the materials. I genuinely appreciate it!
Hcabnettek