I created a very basic WCF service application with the following code in a .svc file:
using System.Collections.Generic; using System.ServiceModel; using System.ServiceModel.Activation; using System.ServiceModel.Web; namespace NamesService { [ServiceContract] [ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class NamesService { List<string> Names = new List<string>(); [OperationContract] [AspNetCacheProfile("CacheFor60Seconds")] [WebGet(UriTemplate="")] public List<string> GetAll() { return Names; } [OperationContract] public void Save(string name) { Names.Add(name); } } }
And web.config looks like this:
<?xml version="1.0"?> <configuration> <system.web> <compilation debug="true" targetFramework="4.0" /> </system.web> <system.serviceModel> <behaviors> <serviceBehaviors> <behavior> <serviceMetadata httpGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="false"/> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" /> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> </system.webServer> <system.web> <caching> <outputCache enableOutputCache="true"/> <outputCacheSettings> <outputCacheProfiles> <add name="CacheFor60Seconds" location="Server" duration="60" varyByParam="" /> </outputCacheProfiles> </outputCacheSettings> </caching> </system.web>
As you can see, the GetAll method was decorated with AspNetCacheProfile, and cacheProfileName refers to the ChacheFor60Seconds section in the web.config file.
I run the following sequence in the WCF test client:
1) Call Save with the parameter "Fred"
2) GetAll is called β "Fred", as expected.
3) Call Save with the parameter "Bob"
4) Call GetAll β this time "Fred" and "Bob" return.
I expected that in the second call to GetAll only "Fred" would be returned, because it should return the cached result from step (2).
I canβt understand what the problem is, so it would be grateful for the help.
source share