JSON限制为1180个字符

时间:2016-02-03 00:26:51

标签: json web-config webmethod svc

我有一个简单的JavaScript JSON请求,它将通过JSON请求发送的对象stringify到我的C#Web服务器。

每当stringy返回的字符串超过1180个字符时,就不会在服务器上调用WebMethod。

根据我的理解,客户端可以通过JSON发送多少字符串数据没有限制。我知道限制是在服务器端,试图接受参数化的请求。

web.config中是否有某处可以将此限制增加到1180?

我当前的配置;

<?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 个答案:

答案 0 :(得分:1)

您需要将webHttpBinding更改为以下内容:

   <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

注意:在ASP.NET兼容模式下,仅增加此值是不够的。您还应该增加httpRuntime的值(请参阅httpRuntime)。

这应该是这样的:

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

(根据需要增加金额)