提高RIA Service結果項目上限

摘要:提高RIA Service結果項目上限

資料量太大會造成WCF無疾而終,接著用了WCF Tracing追問題,由Log挖出了一個關鍵字: MaxItemsInObjectGraph。這才理解,真正讓WCF掛掉的,並不是傳回資料太多讓總長度超出了MaxReceivedMessageSize,而是DataContractSerializer在序列化過程中,達到了RIA Service預設65536個項目的上限。

雖然依一般設計實務,多半建議使用者在瀏覽過程中,用到多少資料再傳多少資料,真正需要一口氣傳回大量資料的場合不多。但如真有需要,可在web.config加入以下設定,就可以將項目上限調到2G囉! 

<system.serviceModel>
   
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
        multipleSiteBindingsEnabled="true" />
   
    <!-- Set maxItemsInObjectGraph -->
    <services>
      <service name="MyNamespace.MyDomainServiceClass"
               behaviorConfiguration="MyWCFConfig"></service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyWCFConfig">
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
   
  </system.serviceModel>