I'm working on an HTTP REST service implemented on WCF. I'd like to set the HTTP cache control headers for my operations appropriately.
我正在研究在WCF上实现的HTTP REST服务。我想适当地为我的操作设置HTTP缓存控制头。
I've seen a few examples that involve using the WebOperationContext.Current.OutgoingResponse
to modify the headers in each method. But let's be honest, that's a pain in the butt, especially since nearly all of my operations are going to use the same cache control policy (no-cache).
我已经看到一些涉及使用WebOperationContext.Current.OutgoingResponse来修改每个方法中的标题的示例。但是说实话,这是一个痛苦的屁股,特别是因为几乎所有的操作都将使用相同的缓存控制策略(无缓存)。
I'm thinking there must be an elegant way to set this. Perhaps a combination of a ServiceBehavior to set a service-level default, and OperationBehaviors to override that for certain operations? Or maybe there's some better way to do this?
我认为必须有一种优雅的方式来设置它。也许ServiceBehavior的组合可以设置服务级别的默认值,而OperationBehaviors可以覆盖某些操作的默认值?或者也许有更好的方法来做到这一点?
1 个解决方案
#1
2
WCF services respect the outputCache setting in the Web.Config. Additionally you can specify OutputCacheProfiles which are also defined in the Web.config and then specify which OutputCacheProfle to use at the method level with decorators.
WCF服务遵循Web.Config中的outputCache设置。此外,您可以指定也在Web.config中定义的OutputCacheProfile,然后指定在方法级别使用装饰器的OutputCacheProfle。
#1
2
WCF services respect the outputCache setting in the Web.Config. Additionally you can specify OutputCacheProfiles which are also defined in the Web.config and then specify which OutputCacheProfle to use at the method level with decorators.
WCF服务遵循Web.Config中的outputCache设置。此外,您可以指定也在Web.config中定义的OutputCacheProfile,然后指定在方法级别使用装饰器的OutputCacheProfle。