WCF service dataContractSerializer maxItemsInObjectGraph in web.config

£可爱£侵袭症+ 提交于 2019-12-05 20:43:34

问题


I am having issues specifying the dataContractSerializer maxItemsInObjectGraph in host's web.config.

 <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>

The above has no effect on my data pull. The server times out because of the large volume of data.

I can however specify the max limit in code and that works

  [ServiceBehavior(MaxItemsInObjectGraph=2147483646, IncludeExceptionDetailInFaults = true)]
  public abstract class MyService : MyService 
  {
   blah...
 }

Does anyone know why I can't make this work through a web.config setting? I would like to keep in the web.config so it is easier for future updates.


回答1:


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.



来源:https://stackoverflow.com/questions/3058202/wcf-service-datacontractserializer-maxitemsinobjectgraph-in-web-config

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!