WCF运行时错误 - "MaxItemsInObjectGraph"太小

当服务器返回的数据量过大时,客户端显示通信错误。

今天遇到的问题是“对象图中需要序列化或反序列化的项目数目超过了上限“65536”。

这个问题需要在WCF系统的服务段和客户端分别修改配置来增加这个上限。

 

服务段修改如下:

<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="default">
          <serviceMetadata />
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="*" behaviorConfiguration="default">
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:1200" />
          </baseAddresses>
        </host>
        <endpoint binding="netTcpBinding" />
        <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>

 

 

客户端修改如下:

<system.serviceModel>
    <client>
      <endpoint name="*" address="net.tcp://127.0.0.1:1200" contract="*" binding="netTcpBinding" behaviorConfiguration="default" />
    </client>
    <behaviors>
      <endpointBehaviors>
        <behavior name="default">
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>

 

posted on 2015-04-22 23:47  hyping  阅读(1152)  评论(0编辑  收藏  举报

导航