JSON参数大小限制

JSON parameter size limit

本文关键字:参数 JSON      更新时间:2023-09-26

我正在使用jQuery$.ajax-json POST调用我的WCF Web服务

其中一个输入参数非常长,超过8000个字节。其中的数据是一个以逗号分隔的GUID列表,如"78dace54-eea-4b31-8a43-dcd01e172d14,ce485e64-e7c6-481c-a24-624371180aa,ede4c606-f743-4e0a-a8cc-59bcffa7feda,f0a81ed1-80db-4f6d-92d7-2fc47759a409"

当该参数的长度为8176字节时,请求成功。当是8213(多一个逗号和GUID)时,请求失败

它从浏览器和Fiddler(HTTP调试代理)失败。我将其添加到Web服务配置中:

<configuration>
<system.web.extensions>
    <scripting>
        <webServices>
            <jsonSerialization maxJsonLength="50000000" recursionLimit="50000"/>
        </webServices>
    </scripting>
</system.web.extensions>

这没有任何区别,对于长度超过8176字节的输入参数,请求仍然失败
该输入参数映射到WCF端的字符串中
我错过了什么?非常感谢。

更新,这解决了我的问题:事实证明,此设置控制JSON消息的总长度

<webServices>
     <jsonSerialization maxJsonLength="50000000" recursionLimit="50000"/>
</webServices>

还有另一个设置可以控制单个参数的最大长度:

<bindings>
  <webHttpBinding>
    <binding name="Binding_Name" maxReceivedMessageSize="900000">
      <readerQuotas maxDepth="32" maxStringContentLength="900000" maxBytesPerRead="900000" maxArrayLength="120000" maxNameTableCharCount="120000"/>
    </binding>
  </webHttpBinding>
</bindings>

此外,请确保设置以下内容:

  <system.web>
     <httpRuntime maxRequestLength="900000"/>

希望这能解决一些头疼的问题!

实际限制似乎是8192个字节。

您必须在system.serviceModel标记:中检查Web.config

 <system.serviceModel>
  <bindings>
   <basicHttpBinding>
     <binding name="Service1Soap" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
     <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
     <security mode="None">
      <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
      <message clientCredentialType="UserName" algorithmSuite="Default"/>
     </security>
    </binding>
   </basicHttpBinding>
  </bindings>

您需要将maxStringContentLength="8192"更改为更大的值。

您还可以发出多个请求,而不是一个请求,以逐页获取GUID列表,在每个请求中使用偏移量参数。例如,要按200页获取GUID列表,第一个请求偏移量为0,第二个请求偏移值为200。。。直到你得到的物品少于200件。

我知道这对您没有多大帮助,但我想指出的是,JSON规范没有设置任何限制;然而,它允许解析器这样做:

实现可能会对其
接受。实现可能会对
的最大深度设置限制嵌套。一个实现可以设置数字范围的限制
实现可以对长度和字符内容设置限制字符串。

RFC4627:JavaScript对象表示法(json)的application/json媒体类型

看看这个答案是否适用于你。