WCF:Maximum number of items that can be serialized or deserialized in an object graph is '65536'.
来源:互联网 发布:淘宝买黑曜石哪家真 编辑:程序博客网 时间:2024/05/21 10:48
出现此错误的原因是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;
}
}
- WCF:Maximum number of items that can be serialized or deserialized in an object graph is '65536'.
- Shortest Path in a weighted Graph where weight of an edge is 1 or 2
- Oracle 12C ORA-01792: maximum number of columns in a table or view is 1000
- In C++, which of the following syntax can be used for instantiating an object named arr of the vecto
- [leetcode323]Number of Connected Components in an Undirected Graph
- LeetCode 323. Number of Connected Components in an Undirected Graph
- leetcode Number of Connected Components in an Undirected Graph
- Number of Connected Components in an Undirected Graph
- Leetcode 323. Number of Connected Components in an Undirected Graph
- LeetCode 323. Number of Connected Components in an Undirected Graph
- LeetCode 323. Number of Connected Components in an Undirected Graph
- Leetcode 323. Number of Connected Components in an Undirected Graph
- No323. Number of Connected Components in an Undirected Graph
- 323. Number of Connected Components in an Undirected Graph
- leetcode323. Number of Connected Components in an Undirected Graph
- Portlet or component that can be uninstalled or stoped in WebSphere Portal
- maximum number of expressions in a list is 1000
- 处理教材:Everything is an object of "Thinking in Java"
- Myeclipse10注册码
- hdu 1233 最小生成树
- Echarts 通过时间轴timeline改变xAxis.data数据进行不合并处理
- C++逗号运算符与逗号表达式
- 一路两输入正与门SN74AHC1G08学习
- WCF:Maximum number of items that can be serialized or deserialized in an object graph is '65536'.
- 四大组件之Service
- Maven学习(八)- 构建MyBatis项目
- JavaScript全局变量和局部变量实例
- 图片保存到本地相册
- 深入理解Neutron -- OpenStack网络实践:概述和基本概念
- 编译安装linux内核步骤
- CSS 优先级法则:
- fastdfs结合nginx做一个网盘