8

我在主机的 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 中,以便将来更新。

4

1 回答 1

12

In your behavior section, add an endpoint behavior with the dataContractSerializer, like so:

<endpointBehaviors>
  <behavior name="LargeQuotaBehavior">
   <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
  </behavior>
</endpointBehaviors>

Then modify your endpoint to use this behavior like so:

<endpoint address="http://localhost/myservice/"
          binding="webHttpBinding"
          bindingConfiguration="webHttpBinding1"
          contract="MyNamespace.IMyService"
          bindingNamespace="MyNamespace"
          behaviorConfiguration="LargeQuotaBehavior">

This should solve your problem.

于 2012-04-10T15:20:45.677 回答