web.config 中的 WCF 服务 dataContractSerializer maxItemsInObjectGraph [英] WCF service dataContractSerializer maxItemsInObjectGraph in web.config

查看:24
本文介绍了web.config 中的 WCF 服务 dataContractSerializer maxItemsInObjectGraph的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在主机的 web.config 中指定 dataContractSerializer maxItemsInObjectGraph 时遇到问题.

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

有谁知道为什么我不能通过 web.config 设置完成这项工作?我想保留在 web.config 中,以便将来更新更容易.

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.

推荐答案

在您的行为部分,使用 dataContractSerializer 添加端点行为,如下所示:

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.

这篇关于web.config 中的 WCF 服务 dataContractSerializer maxItemsInObjectGraph的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆