2010-06-17 83 views
7

我在指定主机web.config中的dataContractSerializer maxItemsInObjectGraph时遇到问题。web.config中的WCF服务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中,以便将来的更新更容易。

+0

我也有这个问题。我想知道为什么没有人回答?感谢能够在代码中设置'ServiceBehavior'的提示,它至少可以让我感动。 – jocull 2011-07-05 06:00:54

+0

你知道maxItemsInObjectGraph只定义了响应中允许的元素的总数,而不是直接响应的大小是啊? (我想如果没有指定它默认为60k xml元素) – 2011-08-10 14:42:32

+0

戴夫,你的问题是否回答了?如果给定的答案解决了您的问题,请将其标记为如此。 – Bardia 2012-12-17 19:56:56

回答

12

在你的行为部分中,添加的终结点行为与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"> 

这应该解决您的问题。

+1

就像一个魅力。谢谢 – SergioM 2014-06-06 07:26:37

+1

今天我遇到了类似的问题。即使WCF在端点行为中存在,Wcf也会抛出超出maxItemsInObjectGraph的异常。然后我将其转移到解决问题的服务行为中.http://stackoverflow.com/questions/26610861/passing-comma-separated-string-value-to-a-wcf-rest-service/26613810#26613810 – user1131926 2014-10-28 17:04:07

相关问题