我在主机的web.config中指定dataContractSerializer maxItemsInObjectGraph时遇到问题.
<behaviors> <serviceBehaviors> <behavior name="beSetting"> <serviceMetadata httpGetEnabled="True"/> <serviceDebug includeExceptionDetailInFaults="True" /> <dataContractSerializer maxItemsInObjectGraph="2147483646"/> </behavior> </serviceBehaviors> </behaviors> <services> <service name="MyNamespace.MyService" behaviorConfiguration="beSetting" > <endpoint address="http://localhost/myservice/" binding="webHttpBinding" bindingConfiguration="webHttpBinding1" contract="MyNamespace.IMyService" bindingNamespace="MyNamespace"> </endpoint> </service> </services>
以上对我的数据拉动没有影响.由于数据量很大,服务器超时.
但是,我可以在代码中指定最大限制并且有效
[ServiceBehavior(MaxItemsInObjectGraph=2147483646,IncludeExceptionDetailInFaults = true)] public abstract class MyService : MyService { blah... }
有谁知道为什么我不能通过web.config设置来完成这项工作?我想保留在web.config中,以便将来更新.
解决方法
在您的行为部分中,使用dataContractSerializer添加端点行为,如下所示:
<endpointBehaviors> <behavior name="LargeQuotaBehavior"> <dataContractSerializer maxItemsInObjectGraph="2147483646"/> </behavior> </endpointBehaviors>
然后修改您的端点以使用此行为,如下所示:
<endpoint address="http://localhost/myservice/" binding="webHttpBinding" bindingConfiguration="webHttpBinding1" contract="MyNamespace.IMyService" bindingNamespace="MyNamespace" behaviorConfiguration="LargeQuotaBehavior">
这应该可以解决您的问题.