【发布时间】:2011-08-17 13:27:38
【问题描述】:
如何为 DataContractJsonSerializer 设置 maxItemsInObjectGraph?
我收到一条错误消息,提示 "Maximum number of items that can be serialized or deserialized in an object graph is '65536'. Change the object graph or increase the MaxItemsInObjectGraph quota."
65536这个数字是从哪里来的。 DataContractJsonSerializer 的 documentation 表示默认值为 Int32.MaxValue。
我尝试在行为配置中设置:
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp />
<dataContractJsonSerializer maxItemsInObjectGraph="500000"/>
</behavior>
</endpointBehaviors>
但我收到如下错误:"Invalid element in configuration. The extension name 'dataContractJsonSerializer' is not registered in the collection at system.serviceModel/extensions/behaviorExtensions."
将行为更改为 <dataContractSerializer maxItemsInObjectGraph="500000"/> 不会出现错误,但不会更改值(这并不奇怪,因为我没有使用 dataContractSerializer)
客户端是使用 ChannelFactory 创建的,因此我无法使用此处描述的 ServiceBehavior 属性here
【问题讨论】:
-
跳过问题中的 dataContractSerializer 位,删除答案:)
标签: wcf webhttpbinding datacontractjsonserializer