Does Silverlight cache web service calls?

后端 未结 4 1474
感动是毒
感动是毒 2021-01-24 18:01

Here\'s the problemo:

My Silverlight application is calling a HTTP web service, using WebClient, called getCampaigns which returns a JSON array of data for Campaign obje

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-24 18:56

    Any HTTP GET requests in Silverlight tend to cached, so if you want to eliminate caching by the client browser use HTTP POST to make web service calls. For example in WCF RIA Domain Services mark your invoke and query methods as such:

    [Invoke(HasSideEffects = true)]
    [Query(HasSideEffects = true)]
    

    HasSideEffects simply states that it should use the POST method to avoid the caching mechanism of the client GET. Remember SL by default uses the browser to make web service calls and by default uses GET which is cacheable. That's why your web service calls to services even outside of RIA are being cached: the browser's seeing you use HTTP GETs and is caching the result.

    The use of GET by default for web service calls is for performance reasons because POST responses are uncacheable by all major browsers per RFC 2616 which states that POST should be an idempotent operation (aka always results in an expected result which caching would break because the result may change over time).

    Other operations in RIA involve setting caching by using LoadBehavior on LoadOperations.

提交回复
热议问题