Setting MaxItemsInObjectGraph for WCF

來源:互聯網
上載者:User

WCF傳輸大資料量的問題,現在網上討論的很多,大多是設定maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"。

這些我也都設定了,但是今天在調試WCF的時候,當我用一個帳號進行操作一切OK。但當我用另外一個帳號操作的時候卻報了錯誤

“對象圖中可以序列化或還原序列化的項目數目上限為“65536”,請更改對象圖或增加 MaxItemsInObjectGraph 的配額”。

最後我一查資料庫才發現先前帳號的資料只有幾百條,而另一個帳號有1W多條,肯定是資料爆了。


下面就來說下如果在服務端和用戶端設定MaxItemsInObjectGraph 

WCF 服務端設定檔

<system.serviceModel>    <services>      <service behaviorConfiguration="BasicServiceBehavior" name="XXX.WCF.Product">        <endpoint address="" binding="customBinding" bindingConfiguration="CompressionChannel" contract="XXX.WCF.IProduct">          <identity>            <dns value="localhost"/>          </identity>        </endpoint>        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>      </service>    </services>    <extensions>      <bindingElementExtensions>        <add          type="WcfExtensions.ServiceModel.Configuration.CompressionElement,WcfExtensions.ServiceModel"          name="compression"/>      </bindingElementExtensions>    </extensions>    <bindings>      <customBinding>        <binding name="CompressionChannel"  receiveTimeout="01:00:00" sendTimeout="01:00:00" >          <compression/>          <textMessageEncoding>            <readerQuotas maxDepth="1024"                          maxStringContentLength="2147483647"                          maxArrayLength="2147483647"                          maxBytesPerRead="2147483647" />          </textMessageEncoding>          <httpTransport maxReceivedMessageSize="2147483647"  />        </binding>      </customBinding>      <basicHttpBinding>        <binding name="BasicHttpWithoutSecurity" transferMode="StreamedResponse" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" receiveTimeout="01:00:00" sendTimeout="01:00:00" >          <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxStringContentLength="2147483647"/>          <security mode="None">            <transport clientCredentialType="None"/>          </security>        </binding>      </basicHttpBinding>    </bindings>    <behaviors>      <serviceBehaviors>        <behavior name="BasicServiceBehavior">          <serviceMetadata httpGetEnabled="true"/>          <serviceDebug includeExceptionDetailInFaults="true"/>          <serviceThrottling maxConcurrentCalls="1000" maxConcurrentInstances="1000" maxConcurrentSessions="1000"/>          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>        </behavior>      </serviceBehaviors>    </behaviors>  </system.serviceModel>

用戶端設定檔

<system.serviceModel>    <extensions>      <bindingElementExtensions>        <add          type="WcfExtensions.ServiceModel.Configuration.CompressionElement,WcfExtensions.ServiceModel"          name="compression"/>      </bindingElementExtensions>    </extensions>    <bindings>      <customBinding>        <binding name="CompressionChannel" >          <compression/>          <textMessageEncoding>            <readerQuotas maxDepth="32"                          maxStringContentLength="2147483647"                          maxArrayLength="2147483647"                          maxBytesPerRead="2147483647"/>          </textMessageEncoding>          <httpTransport maxReceivedMessageSize="2147483647" />        </binding>      </customBinding>      <basicHttpBinding>        <binding name="BasicHttpBinding_IProduct" closeTimeout="00:01:00"                         openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"                         allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"                         maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"                         messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"                         useDefaultWebProxy="true">          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"              maxBytesPerRead="4096" maxNameTableCharCount="16384" />          <security mode="None">            <transport clientCredentialType="None" proxyCredentialType="None"                realm="" />            <message clientCredentialType="UserName" algorithmSuite="Default" />          </security>        </binding>      </basicHttpBinding>    </bindings>    <client>      <endpoint address="http://dev.xxx.com/Product.svc"  behaviorConfiguration="BasicServiceBehavior"                binding="customBinding" bindingConfiguration="CompressionChannel"                 contract="ProductService.IProdcut" name="BasicHttpBinding_IProduct" />    </client>    <behaviors>     <endpointBehaviors>        <behavior name="BasicServiceBehavior">          <callbackDebug includeExceptionDetailInFaults="true"/>          <callbackTimeouts transactionTimeout="00:10:00"/>          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>        </behavior>      </endpointBehaviors>    </behaviors>  </system.serviceModel>

這樣伺服器端和用戶端配置後,就可以提高最大傳輸量了。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.