【问题标题】:JSON Limited to 1180 CharactersJSON 限制为 1180 个字符
【发布时间】:2016-02-03 00:26:51
【问题描述】:

我有一个简单的 JavaScript JSON 请求,它是一个通过 JSON 请求发送到我的 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>

【问题讨论】:

    标签: json web-config webmethod svc


    【解决方案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 &lt;webHttpBinding&gt; here

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

    这应该是这样的:

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

    (根据需要增加数量)

    【讨论】:

    • 很高兴,非常感谢您一直以来的支持。这确实达到了我的极限,但只达到了 ~1250 :(
    • 很高兴,我感激不尽。非常感谢您的帮助
    • 很高兴有帮助:)
    猜你喜欢
    • 2016-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-04
    • 2011-05-12
    • 1970-01-01
    相关资源
    最近更新 更多