微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – JSON参数大小限制

我使用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 config中:
<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"/>

希望这里有一些头疼!

解决方法

实际限制似乎是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,第二个以offset = 200,…直到您获得少于200个项目.

原文地址:https://www.jb51.cc/js/152535.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐