ASP.NET Web 服务最大数组长度配额

Posted

技术标签:

【中文标题】ASP.NET Web 服务最大数组长度配额【英文标题】:ASP.NET web service maximum array length quota 【发布时间】:2013-09-15 11:06:32 【问题描述】:

当在客户端接收文件时,我在 ASP.NET Web 服务中遇到此错误:

The maximum array length quota (16384) has been exceeded while reading XML data. This quota may be increased by changing the MaxArrayLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader.

我知道如何为 WCF 服务解决此问题。但是在 ASP.NET Web 服务中我必须在哪里更改 maxArrayLengthmaxStringContentLength

编辑:

在我的 web.config(服务器)中,没有任何特定于 Web 服务的内容。

这是我在 app.config(客户端)中的绑定:

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="OMCServiceSoap" maxReceivedMessageSize="10000000" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost/1820/Service/OMCService.asmx"
        binding="basicHttpBinding" bindingConfiguration="OMCServiceSoap"
        contract="ServiceReference.OMCServiceSoap" name="OMCServiceSoap" />
    </client>
  </system.serviceModel> 

【问题讨论】:

您确定此错误发生在服务器上,而不是客户端上吗?看起来问题出在阅读方面。 @jlew。是的。你说的对。它在客户端上。 那么您的客户使用的是服务参考还是网络参考? 【参考方案1】:

试试这个

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="OMCServiceSoap" maxReceivedMessageSize="10000000">
     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647"/>
    </binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://localhost/1820/Service/OMCService.asmx"
    binding="basicHttpBinding" bindingConfiguration="OMCServiceSoap"
    contract="ServiceReference.OMCServiceSoap" name="OMCServiceSoap" />
</client>
</system.serviceModel> 

【讨论】:

谢谢。有用。由于我的绑定标签为空,我找不到这个。非常感谢。【参考方案2】:

&lt;system.serviceModel&gt; 下,如下所示

    <bindings>
          <basicHttpBinding>
                 <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                maxBytesPerRead="4096" maxNameTableCharCount="16384" />
 </basicHttpBinding>
    </bindings>

【讨论】:

basicHttpBinding 元素没有 readerQuotas 子元素。

以上是关于ASP.NET Web 服务最大数组长度配额的主要内容,如果未能解决你的问题,请参考以下文章

ASP.Net 多行文本框最大长度

通过 JSON 对象将 Session 对象中的字节数组传递给 Web 服务(Asp.Net 2.0 asmx)

asp.net用多线程上传大文件(500MB~2G)

Json 对象 Asp.net Core 3.1 的最大长度

增加 asp.net 核心中的最大 url 长度

超出最大请求长度