2016-02-03 35 views
0

我有一個簡單的JavaScript JSON請求,它將stringify的對象通過JSON請求發送到我的C#Web服務器。JSON限制爲1180個字符

只要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

youll需要你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"/> 

(根據需要增加數量)

+0

欣喜,非常感謝你對我們的一貫支持。 這做了我的極限,但只有〜1250 :( – clamchoda

+0

@ clamchoda請參閱我的更新 – DelightedD0D

+1

很高興,我不能夠感謝你足夠。我非常感謝您的幫助 – clamchoda