JSON Limited to 1180 Characters

你说的曾经没有我的故事 提交于 2019-12-12 01:41:51

问题


I have a simple JavaScript JSON request which stringify's an object to send via a JSON request to my C# Web server.

Whenever the string returned by stringy is over 1180 characters, the WebMethod is not called on the server.

From my understanding, there is no limit on how much string data the client can send via JSON. I understand that the limitation is on the server end, trying to accept the paramaterized request.

Is there somewhere in the web.config that I can increase this limit of 1180?

My current config;

<?xml version="1.0"?>
<configuration>
  <connectionStrings>
    <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;initial catalog=aspnetdb" providerName="System.Data.SqlClient"/>
    <add name="ApplicationServices2" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;initial catalog=trimweb" providerName="System.Data.SqlClient"/>
    <add name="ApplicationServices3" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;initial catalog=Customers" providerName="System.Data.SqlClient"/>
    <add name="ApplicationServices4" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;initial catalog=OrderUpdate;User ID=test1;Password=test1;" providerName="System.Data.SqlClient"/>
  </connectionStrings>
    <system.serviceModel>
      <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

      <behaviors>
        <endpointBehaviors>
          <behavior name="webHttpBehavior">
            <webHttp />
          </behavior>
        </endpointBehaviors>
      </behaviors>
      <bindings>
        <webHttpBinding>
          <binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true" />
        </webHttpBinding>

      </bindings>
      <services>
        <service name="ServiceSite.CustomersService">
          <endpoint address="" binding="webHttpBinding"
                    bindingConfiguration="webHttpBindingWithJsonP" contract="ServiceSite.CustomersService"
                    behaviorConfiguration="webHttpBehavior"/>
        </service>
      </services>
    </system.serviceModel>

    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>
    <system.webServer>
      <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>

</configuration>

回答1:


Youll need to change your webHttpBinding to something like the below:

   <webHttpBinding>
      <binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true" maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000"/>
      <readerQuotas maxDepth="32" maxArrayLength="200000000" maxStringContentLength="200000000"/>
   </webHttpBinding>

See the docs for <webHttpBinding> here

Note: Increasing this value alone is not sufficient in ASP.NET compatible mode. You should also increase the value of httpRuntime (see httpRuntime).

This should be something like:

<httpRuntime 
   maxQueryStringLength = "2048"
   maxRequestLength="4096"
   maxUrlLength = "260"
   requestLengthDiskThreshold="80"/>

(Increase amounts as needed)



来源:https://stackoverflow.com/questions/35166381/json-limited-to-1180-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!