Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting HTTP cache control headers in WCF service

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.

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).

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?

like image 649
Brian Reischl Avatar asked Mar 16 '12 01:03

Brian Reischl


1 Answers

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.

like image 130
MyItchyChin Avatar answered Sep 27 '22 22:09

MyItchyChin