开发者

CacheDuration in WebMethod ignored

I try to cache a webmethod of a webservice. By following the documentation, I h开发者_如何学Pythonave tried to add the CacheDuration attribute, and made a test :

[WebMethod(CacheDuration = 180)]
public int TestCacheDuration()
{           
   return new Random().Next();
}

For each call of the webmethod, I have a different response, so it is not cached.

Is it normal ?

Thanks for your answers!


This is clearly explained in MSDN forums:

There are two issues that can affect output caching in an ASP.NET 2.0 Web service application.

In ASP.NET 2.0 the HTTP method of the test page has changed from GET to POST. However, POSTs are not normally cached. If you change the test page in an ASP.NET 2.0 Web service application to use GET, caching works properly.

In addition, HTTP indicates that a user agent (the browser or calling application) should be able to override server caching by setting the "Cache-Control" to "no-cache". ASP.NET applications, therefore, ignore cached results when they find a "no-cache" header.

and also:

Use protocols element under webSerices element in web.config:

http://msdn2.microsoft.com/en-us/library/ms228319(VS.85).aspx

source: http://social.msdn.microsoft.com/forums/en-US/asmxandxml/thread/3765f1e2-0ff5-4840-afa2-e85b3d909cd1

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜