2013-12-19 67 views
1

我正在研究一個WCF webHttpBinding Web服務a,它將實時數據傳回給顯示板,我遇到的問題是來自數據庫的數據似乎正在被緩存。WCF webHttpBinding服務和禁用數據庫緩存

我正在開發使用.Net4.5和IISExpress 7

應用我有在enableOutputCache值爲false和aspNetCompatibilityEnabled值設置爲false,但回到仍緩存中的數據。

配置文件

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections> 

    <system.web> 

    <compilation debug="true" targetFramework="4.5" /> 
    <httpRuntime targetFramework="4.5" /> 

    <caching> 
     <outputCache enableOutputCache="false"/> 
    </caching> 

    </system.web> 

    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> 
    <providers> 
     <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
    </providers> 
    </entityFramework> 

    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 

    <connectionStrings> 
    <add name="JcbManufacturingPortalEntities" connectionString="metadata=res://*/xxxxx.csdl|res://*xxxxx.ssdl|res://*/xxxxx.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=xxxxx;initial catalog=xxxxx;persist security info=True;user id=xxxxx;password=xxxxx;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" /> 
    </connectionStrings> 


    <system.serviceModel> 
    <services> 
     <service behaviorConfiguration="AndonRest" name="Jmp.Andon.Service.AndonService"> 
     <endpoint binding="webHttpBinding" bindingConfiguration="RestBinding" name="Jmp.Andon.Service.AndonService" contract="Jmp.Andon.Service.IAndonService" behaviorConfiguration="webBehaviour" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="https://localhost:44302/" /> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    <behaviors> 
     <endpointBehaviors> 
     <behavior name="webBehaviour"> 
      <dataContractSerializer maxItemsInObjectGraph="655360" /> 
      <webHttp /> 
     </behavior> 
     </endpointBehaviors> 
     <serviceBehaviors> 
     <behavior name="AndonRest"> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 
     <behavior name=""> 
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" /> 
    <bindings> 
     <webHttpBinding> 
     <binding name="RestBinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"> 
      <security mode="Transport" /> 
     </binding> 
     </webHttpBinding> 
    </bindings> 
    </system.serviceModel> 

</configuration> 
+1

您可以記錄您的服務調用和它從數據庫接收的數據,以確認您的設置的哪部分緩存數據? – nvoigt

+0

其實體框架調用數據庫。 –

+0

認爲問題在於我正在使用單個緩存的DBContext。 –

回答

3

根本的問題是,我是用每一個呼叫實例單緩存的DbContext。

爲了防止數據庫上下文高速緩存數據,我實現了從System.Data.Entity dll的AsNoTracking擴展名。

return (ctx.CollectionValues.Where(l => l.LayoutID.Equals(layoutID)) 
       .Select(v => new MeasureValueDto { MeasureID = v.ScreenItemID, DataValue = v.Value }).AsNoTracking().ToList());