WCF:Maximum number of items that can be serialized or deserialized in an object graph is '65536'.
2015-11-19 16:36
1466 查看
出现此错误的原因是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;
}
}
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;
}
}
相关文章推荐
- Android Activity如何保存和恢复Object
- 关于错误 libstdc++.so.6:cannot open shared object file 和 libstdc++.so.6: wrong ELF class 的解决和思考
- underscore源码解析(object)
- Bucket不为空,请检查该Bucket是否包含未删除的Object或者未成功的Multipart碎片
- 初学Objective-C
- Objective-C 编码建议
- Objective-C基础-类方法的学习
- iOS开发系列—Objective-C之Foundation框架
- Objective-C 编码建议
- Objective-C 编码建议
- Java Object 类源码分析
- Objective-c:类目、延展、协议
- object references an unsaved transient instance
- _nm_object_get_property: Error getting 'State' for /org/freedesktop/NetworkManager/ActiveConnection/
- Java不定参数Object… obj
- [2015.11.18] Objective-c UIScrollView 页面跳转 线传值
- Objective-C 学习笔记 - 第1章 入门
- Objective-C 学习笔记 - 第1章 入门
- Object-C排序的几种方法
- Geometry-Shader Object