首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WCF webHttpBinding服务和禁用DB缓存

WCF webHttpBinding服务和禁用DB缓存
EN

Stack Overflow用户
提问于 2013-12-19 10:54:47
回答 1查看 863关注 0票数 1

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

我正在使用.Net4.5和IISExpress 7开发应用程序。

我的enableOutputCache值为false,aspNetCompatibilityEnabled值为false,但返回的数据仍然被缓存。

Config文件

代码语言:javascript
复制
<?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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-19 11:26:40

根本的问题是,对于每个调用实例,我都使用了一个缓存的DBContext。

为了防止DB上下文缓存数据,我实现了来自AsNoTracking dll的System.Data.Entity扩展。

代码语言:javascript
复制
  return (ctx.CollectionValues.Where(l => l.LayoutID.Equals(layoutID))
                .Select(v => new MeasureValueDto { MeasureID = v.ScreenItemID, DataValue = v.Value }).AsNoTracking().ToList());
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20679787

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档