簡體   English   中英

WCF webHttpBinding服務和禁用數據庫緩存

[英]WCF webHttpBinding service and disabling DB caching

我正在開發一個WCF webHttpBinding Web服務,它將實時數據傳遞回顯示板,而我遇到的問題是數據庫中的數據似乎正在被緩存。

我正在使用.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>

根本問題是我為每個調用實例使用了一個緩存的DBContext。

為了防止DB上下文緩存數據,我從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());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM