Dmi*_*ski 10 javascript wcf jquery post 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配置:
<configuration>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="50000000" recursionLimit="50000"/>
</webServices>
</scripting>
</system.web.extensions>
Run Code Online (Sandbox Code Playgroud)
这没有任何区别,对于超过8176字节长的输入参数,请求仍然失败.
该输入参数映射到WCF端的String.
我错过了什么?谢谢!
更新,这解决了我的问题:原来这个设置控制总JSON消息长度
<webServices>
<jsonSerialization maxJsonLength="50000000" recursionLimit="50000"/>
</webServices>
Run Code Online (Sandbox Code Playgroud)
还有另一个设置可控制各个参数的最大长度:
<bindings>
<webHttpBinding>
<binding name="Binding_Name" maxReceivedMessageSize="900000">
<readerQuotas maxDepth="32" maxStringContentLength="900000" maxBytesPerRead="900000" maxArrayLength="120000" maxNameTableCharCount="120000"/>
</binding>
</webHttpBinding>
</bindings>
Run Code Online (Sandbox Code Playgroud)
另外,请务必设置:
<system.web>
<httpRuntime maxRequestLength="900000"/>
Run Code Online (Sandbox Code Playgroud)
希望这能解决一些令人头疼的问题!
实际限制似乎是 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>
Run Code Online (Sandbox Code Playgroud)
您需要将maxStringContentLength="8192"更改为更大的值。
您还可以发出多个请求,而不是一个请求来逐页获取 GUID 列表,并在每个请求中使用偏移量参数。例如,要获取 200 页的 GUID 列表,请首先使用 offset=0 请求,第二个请求使用 offset=200,...直到获得少于 200 个项目。