WCF WebHttpBinding 服务和禁用数据库缓存



我正在开发一个WCF webHttpBinding Web服务,该服务将实时数据传递回显示板,我遇到的问题是数据库中的数据似乎正在缓存。

我正在使用 .Net4.5 和 IISExpress 7。

我将 enableOutputCache 值设置为 false,将

aspNetCompatibility Enable 值设置为 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>

根本问题是我为每个调用实例使用单个缓存的 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());

相关内容

  • 没有找到相关文章

最新更新