简体   繁体   English

DataContractSerializer.MaxItemsInObjectGraph属性的含义

[英]The meaning of DataContractSerializer.MaxItemsInObjectGraph property

One of methods of our WCF service throws exception on production environment: 我们的WCF服务的一种方法会在生产环境中抛出异常:

The formatter threw an exception while trying to deserialize the message: There was an 格式化程序在尝试反序列化消息时抛出异常:有一个
error while trying to deserialize parameter http: //our_schema:GetSomeListResult. 尝试反序列化参数http:// our_schema:GetSomeListResult时出错。 The InnerException message was 'Maximum number of items that can be serialized or deserialized in an object graph is '65536'. InnerException消息是'对象图中可以序列化或反序列化的最大项数是'65536'。 Change the object graph or increase the MaxItemsInObjectGraph quota. 更改对象图或增加MaxItemsInObjectGraph配额。

The method GetSomeList returns a list of objects (15 properties - ints, enums, strings, DateTimes) and it has about 6k elements. GetSomeList方法返回一个对象列表(15个属性 - 整数,枚举,字符串,DateTimes),它有大约6k个元素。 However, the same service configuration doesn't lead to this error on my local machine and on test environment. 但是,相同的服务配置不会在我的本地计算机和测试环境中导致此错误。 I know how to fix this error: 我知道如何解决这个错误:

    <behavior name="basicEndpointBehavior">
    <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    </behavior>

but I don't understand it's nature. 但我不明白它的本质。

So what is the real number of objects in serialized/deserialized array? 那么序列化/反序列化数组中的实际对象数是多少? List.Count? List.Count? List.Count*(number of properties)? List.Count *(属性数量)? If the formula is List.Count*(number of properties), number of objects = 6k*15=90k, which is greater than 65536. Why does this method call work fine locally with the same size of array? 如果公式是List.Count *(属性数),则对象数= 6k * 15 = 90k,大于65536.为什么此方法调用在本地使用相同大小的数组工作正常?

It's the number of objects - ie the number of instances of things that need to get serialized. 它是对象的数量 - 即需要序列化的事物的实例数。 If all properties of objects in the list returns just a primitive object, then the number should be List.Count * (number of properties + 1) (each item in the list is an object, and each property of an item is another one). 如果列表中对象的所有属性只返回一个原始对象,则该数字应为List.Count * (number of properties + 1) (列表中的每个项目都是一个对象,项目的每个属性都是另一个) 。

The number could be significantly lower if you've set EmitDefaultValue to false , but odds are you're not doing this. 如果你将EmitDefaultValue设置为false ,那么这个数字可能会显着降低,但你可能没有这样做。

As to why the behaviour might be different locally vs. production, I've seen situations where the serializer config only applies to HTTP, and you have to set it separately for HTTPS; 至于为什么本地行为可能与生产不同,我看到串行器配置仅适用于HTTP的情况,你必须为HTTPS单独设置它; could this be the problem? 这可能是问题吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 DataContractSerializer未序列化一个属性 - DataContractSerializer not serializing one property 使用DataContractSerializer序列化overriden属性 - Serialize overriden property with DataContractSerializer WCF DataContractSerializer具有长属性名称的性能 - WCF DataContractSerializer Performance with long property names 使用DataContractSerializer时设置属性的初始值 - Setting the initial value of a property when using DataContractSerializer DataContractSerializer:由于属性类型更改而无法反序列化 - DataContractSerializer: can't deserialize because of changed property type DataContractSerializer将对象列表中重复的属性引用反序列化为null - DataContractSerializer deserialize repeated property references as null in a list of objects 使用 DataContractSerializer 进行序列化时如何忽略属性? - How can I ignore a property when serializing using the DataContractSerializer? 有没有办法让 XmlSerializer(或 DataContractSerializer)序列化可观察的 object 的属性? - Is there a way to get XmlSerializer (or DataContractSerializer) to serialise the property of an observable object? 以编程方式设置MaxItemsInObjectGraph - Programmatically set the MaxItemsInObjectGraph Wcf忽略MaxItemsInObjectGraph值 - Wcf ignore MaxItemsInObjectGraph value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM