Setting MaxItemsInObjectGraph for WCF

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>
这样服务器端和客户端配置后,就可以提高最大传输量了。



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值