返回的对象太多时会出现异常:
格式化程序在尝试反序列化消息时抛出异常:尝试反序列化参数http://.../Contract:GetBlaBlaResult时出错 . InnerException消息是'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. ' . 有关更多详细信息,请参阅InnerException .
我查了一下并添加了服务器端的行为:
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
...
在客户端:
<behaviors>
<endpointBehaviors>
<behavior name="maxItems">
<dataContractSerializer maxItemsInObjectGraph="2147483646" />
</behavior>
</endpointBehaviors>
</behaviors>
但它似乎被忽略了,异常不断出现 .
问题是我使用XmlSerializer(对于元素中的属性):
[ServiceContract(Namespace = "http://BlaBla.com/webservices/BlaBlaService")]
[XmlSerializerFormat(SupportFaults = true)]
public interface IBlaBlaServices
{
[OperationContract]
BlaBlaResponse GetBlaBla(BlaBlaRequestMessage searchBlaBlaRequest);
}
正如您所看到的,异常是指dataContractSerializer(我上面添加的配置也是如此) .
XmlSerializer会搞砸事情吗?
有人可以提出建议吗?
非常感谢 :)
1 回答
只是为了确保,您是将MyServiceBehavior行为应用于服务配置中的服务定义,将maxItems行为应用于客户端配置中的 endpoints 定义(behaviorConfiguration属性)?