WCF:Maximum number of items that can be serialized or deserialized in an object graph is '65536'.

原创 2015年11月19日 16:36:27

出现此错误的原因是WCF默认的序列化值不够,导致查询大数量的时候报错,解决的方法是修改序列化的值,可在配置文件中修改,或者在代码中修改:

1、改配置文件:

在behaviors中添加<dataContractSerializer maxItemsInObjectGraph="2147483647"/>,如下:

<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
          <!--序列化大小设置-->
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>

客户端配置文件也添加<dataContractSerializer maxItemsInObjectGraph="2147483647"/>

2、代码修改,在代理类中添加如下代码:

服务器端:

ServiceHost host = new ServiceHost(serviceType, uri);
foreach (IServiceBehavior behavior in host.Description.Behaviors)
{
if (behavior is ServiceBehaviorAttribute)
{
(behavior as ServiceBehaviorAttribute).MaxItemsInObjectGraph = int.MaxValue;
}
}

客户端:

ChannelFactory模式如下修改:

ChannelFactory<T> channelFactory = new ChannelFactory<T>(binding);
foreach (OperationDescription op in channelFactory.Endpoint.Contract.Operations)
{
DataContractSerializerOperationBehavior dataContractBehavior = op.Behaviors.Find<DataContractSerializerOperationBehavior>() as DataContractSerializerOperationBehavior;
if (dataContractBehavior != null)
{
dataContractBehavior.MaxItemsInObjectGraph = int.MaxValue;
}
}

ClientBase模式做如下修改:

EndpointAddress address = new EndpointAddress("http://10.0.0.1/TestService.svc/PC");
            WSHttpBinding binding = new WSHttpBinding();

Service service = new Service(binding, address);

foreach (OperationDescription op in service .Endpoint.Contract.Operations)
            {


                DataContractSerializerOperationBehavior dataContractBehavior = op.Behaviors.Find<DataContractSerializerOperationBehavior>() as DataContractSerializerOperationBehavior;
                if (dataContractBehavior != null)
                {
                    dataContractBehavior.MaxItemsInObjectGraph = int.MaxValue;
                }
            }


(一)Unity5.0新特性------转载自官方-unity5.0正式发布了,看看带来哪些重要的新特性!

Unity 5.0Unity 5.0 is our biggest and boldest release ever. Powerful new features in Unity 5 include...
  • u010019717
  • u010019717
  • 2015年03月04日 11:26
  • 35232

C++语法总结,语法查询

How to Program in C++ http://cs.fit.edu/~mmahoney/cse2050/how2cpp.html How to Program ...
  • sergery
  • sergery
  • 2013年06月28日 11:38
  • 54590

Nodejs源码解析之Buffer

今天源码分析一下Nodejs的核心模块Buffer, 官方文档https://nodejs.org/api/buffer.html 在分析源码前,以下问题需要说明: Buffer可以看作是原始数据的...
  • leoleocs
  • leoleocs
  • 2015年12月23日 17:36
  • 2468

What can I learn right now in just 10 minutes that could be useful for the rest of my life?

What can I learn right now in just 10 minutes that could be useful for the rest of my life?
  • miss1993
  • miss1993
  • 2015年03月18日 17:21
  • 406

《How hard can it be? Estimating the difficulty of visual search in an image》和 PPT

《How hard can it be? Estimating the difficulty of visual search in an image》发表于2016年CVPR上,这篇文章是老师推荐的...
  • ali197294332
  • ali197294332
  • 2016年07月17日 17:34
  • 947

LeetCode 323. Number of Connected Components in an Undirected Graph(连通分量)

原题网址:https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph/ Given n ...
  • jmspan
  • jmspan
  • 2016年04月25日 02:50
  • 763

Incorrect decrement of the reference count of an object that is not owned at this point by the calle

Incorrect decrement of the reference count of an object that is not owned at this point by the cal...
  • Liar0606
  • Liar0606
  • 2014年06月13日 11:43
  • 868

LeetCode 323. Number of Connected Components in an Undirected Graph

Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes),...
  • xinqrs01
  • xinqrs01
  • 2017年01月11日 09:09
  • 121

An application which is an example of graphics and can be us

  • 2006年02月23日 09:05
  • 8KB
  • 下载

Is there a limit to the number of columns in an HBase row?

Quora上一个哥们提出下面这个问题,之前其实读过的不过没怎么在意comments,而且自己还亲自测试了一下这个问题确定当一个row很大的时候不会发生拆分的。今天又看了一遍,其实这里面已经包含了很多信...
  • macyang
  • macyang
  • 2011年03月04日 09:28
  • 1082
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:WCF:Maximum number of items that can be serialized or deserialized in an object graph is '65536'.
举报原因:
原因补充:

(最多只允许输入30个字)