【问题标题】:JSON parameter size limitJSON 参数大小限制
【发布时间】:2012-02-25 15:05:14
【问题描述】:

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

输入参数之一很长 - 超过 8000 个字节。其中的数据是以逗号分隔的 GUID 列表,例如“78dace54-1eea-4b31-8a43-dcd01e172d14,ce485e64-e7c6-481c-a424-2624371180aa,ede4c606-f743-4e0a-a8cc-59bcffa7db-f0a81ed 4f6d-92d7-2fc47759a409"。

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

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

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

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

【问题讨论】:

  • 您是否尝试过将该 GUID 列表作为 JSON 数组传递?
  • IMO 它可能是browser thing
  • 请求成功后,在 Fiddler 中看到的 http 请求/回复的实际大小是多少?
  • 我有同样的问题,但是当我测量整个 JSON.stringify 输出时,我发现限制是 65536,或者正好是 16 位。这不可能是巧合。 C# 或 JSON.stringify 必须有一个限制集。

标签: javascript jquery wcf json post


【解决方案1】:

实际的限制似乎是 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>

您需要将 ma​​xStringContentLength="8192" 更改为更大的值。

您也可以发出多个请求而不是一个请求来逐页获取 GUID 列表,在每个请求中使用偏移量参数。例如,要按 200 页获取 GUID 列表,首先请求偏移量 = 0,第二个请求偏移量 = 200,...直到获得少于 200 个项目。

【讨论】:

    【解决方案2】:

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

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

    RFC4627: The application/json Media Type for JavaScript Object Notation (JSON)

    看看this answer是否适用于你。

    【讨论】:

      猜你喜欢
      • 2012-11-10
      • 1970-01-01
      • 2018-04-21
      • 1970-01-01
      • 2013-11-10
      • 1970-01-01
      • 1970-01-01
      • 2018-06-19
      • 2021-09-05
      相关资源
      最近更新 更多