wcf - maxItemsInObjectGraph 被忽略

标签 wcf

我有一个 WCF 服务的问题,它试图序列化太多的数据。从跟踪中,我收到一个错误,指出可以序列化或反序列化的最大元素数为“65536”,请尝试增加 MaxItemsInObjectGraph 配额。

所以我去修改了这个值,但它只是被忽略了(错误是相同的,具有相同的数字)。所有这些都是服务器端的。我目前正在通过 wget 调用该服务。

我的网络配置是这样的:

<system.serviceModel>  
  <behaviors>
   <serviceBehaviors>
    <behavior name="AlgoMap.Web.MapService.MapServiceBehavior">
       <dataContractSerializer maxItemsInObjectGraph="131072" />
       <serviceMetadata httpGetEnabled="true" />
       <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
   </serviceBehaviors>
  </behaviors>
  <bindings>
   <customBinding>
    <binding name="customBinding0" closeTimeout="00:02:00" openTimeout="00:02:00" receiveTimeout="00:02:00">
      <binaryMessageEncoding>
        <readerQuotas maxDepth="64" maxStringContentLength="16384"
                                maxArrayLength="16384" maxBytesPerRead="16384"
                                maxNameTableCharCount="16384" />
      </binaryMessageEncoding>
      <httpTransport />
    </binding>
   </customBinding>
  </bindings>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
  <services>
   <service behaviorConfiguration="AlgoMap.Web.MapService.MapServiceBehavior"
    name="AlgoMap.Web.MapService.MapService">
    <endpoint address="" binding="customBinding" bindingConfiguration="customBinding0"
     contract="AlgoMap.Web.MapService.MapService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
   </service>
  </services>
 </system.serviceModel>



版本 2,也不起作用:
 <system.serviceModel>  
  <behaviors>

    <endpointBehaviors>
      <behavior name="AlgoMap.Web.MapService.MapServiceEndpointBehavior">
         <dataContractSerializer maxItemsInObjectGraph="131072" />
      </behavior>
    </endpointBehaviors>

   <serviceBehaviors>
    <behavior name="AlgoMap.Web.MapService.MapServiceBehavior">
       <serviceMetadata httpGetEnabled="true" />
       <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
   </serviceBehaviors>
  </behaviors>
  <bindings>
   <customBinding>
    <binding name="customBinding0" closeTimeout="00:02:00" openTimeout="00:02:00" receiveTimeout="00:02:00">
      <binaryMessageEncoding>
        <readerQuotas maxDepth="64" maxStringContentLength="16384"
                                maxArrayLength="16384" maxBytesPerRead="16384"
                                maxNameTableCharCount="16384" />
      </binaryMessageEncoding>
      <httpTransport />
    </binding>
   </customBinding>
  </bindings>

  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
  <services>
   <service behaviorConfiguration="AlgoMap.Web.MapService.MapServiceBehavior"
    name="AlgoMap.Web.MapService.MapService">
     <endpoint 
        address="" binding="customBinding" bindingConfiguration="customBinding0"
        contract="AlgoMap.Web.MapService.MapService" 
        behaviorConfiguration="AlgoMap.Web.MapService.MapServiceEndpointBehavior" />
    <endpoint 
        address="mex" binding="mexHttpBinding" contract="IMetadataExchange"  
        behaviorConfiguration="AlgoMap.Web.MapService.MapServiceEndpointBehavior" />
   </service>
  </services>
 </system.serviceModel>

有人可以帮忙吗??
谢谢!!

最佳答案

放在 web.config 中的任何设置都被愉快地忽略了,我还没有找到原因。但我找到了一个解决方法,即将 MaxItemsInObjectGraph 设为 类(class)装修 .这完美地工作:

// MyService.svc
// using...

namespace MyNamespace {
  [ServiceContract]
  [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
  [ServiceBehavior(MaxItemsInObjectGraph = 65536000)]
  public class MyWebService {

    [OperationContract]
    [WebGet(UriTemplate = "tree/{sessionId}", ResponseFormat = WebMessageFormat.Json)]
    public MyData GetTree(string sessionId) {
    ...
...

关于wcf - maxItemsInObjectGraph 被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2325321/

相关文章:

.net - InstanceContextMode.Single 可用于 WCF basicHttpBinding 吗?

c# - 如何使用 WCF 签署 SOAP 请求

.net - WCF UriTemplate 不会匹配带有斜杠(/)的单个字符串参数

wcf - WCF中使用session的目的是什么

c# - 带有 'same port' 的 WCF 多主机 header 导致错误

wcf - Host Header 可以和 URL 不同吗

wpf - 取消异步 WCF 请求的最佳方法是什么?

c# - 通过 HttpClient 将空主体发布到 REST API

asp.net-mvc - ASP.NET MVC 4 到 WCF 数据服务