简体   繁体   中英

wcf service method caching not working

I am trying to implement caching in WCF service. Please find the below code.

Contract :

    [WebGet(UriTemplate = "")]
    [OperationContract]
    int GetNumber(); 

Contract implementation :

   [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
   public class Service1 : IService1
   {    
[AspNetCacheProfile("MoviesCollection")]
    [WebGet(UriTemplate = "")]
    public int GetNumber()
    {
        Random number = new Random();
        return number.Next(1, 899);
    }
  }

Web.Config

<caching>
  <outputCache enableOutputCache="true"/>
  <outputCacheSettings>
    <outputCacheProfiles>
      <add name="MoviesCollection" location="Server" duration="6000" varyByParam="none"
       enabled="true"/>
    </outputCacheProfiles>
  </outputCacheSettings>
</caching>

I am using WCF service application and not WCF service library. Please let me know what i am missing here. thanks.

Regards, Jebli

“要启用WEB HTTP服务缓存,必须首先启用ASP.NET兼容性”。从MSDN中检查此链接。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM