JSON参数大小限制

时间:2012-02-02 22:46:59

标签: javascript jquery wcf json post

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

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

当该参数 8176字节长时,请求成功。如果 8213 (另外一个逗号和GUID) - 请求失败

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

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

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

更新,这解决了我的问题: 事实证明,此设置控制总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"/>

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

1 个答案:

答案 0 :(得分:2)

实际限制似乎是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”更改为更大的值。

您也可以使用每个请求中的offset参数,多个请求而不是一个请求逐页获取GUID列表。例如,要获取页面为200的GUID列表,第一个请求偏移= 0,第二个请求偏移= 200,...直到您获得少于200个项目。