简体   繁体   中英

ajax call - outofmemory exception on returning big json string in asmx webmethod

Exception of type 'System.OutOfMemoryException' was thrown:

at System.Text.StringBuilder.ToString() at System.Web.Util.HttpEncoder.JavaScriptStringEncode(String value) at System.Web.HttpUtility.JavaScriptStringEncode(String value, Boolean addDoubleQuotes) at System.Web.Script.Serialization.JavaScriptSerializer.SerializeString(String input, StringBuilder sb) at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember)
at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember)
at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat)
at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat) at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)
at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)

json string that returned is big(more than 5MB), what are the solution for this problem?

By default, it is possible to send or receive 4MB of data(Maximum). If you want to send more than that, you have to change the maxMessageLength in your web.config file like below.

 <configuration>

  <system.web>

     <httpRuntime maxMessageLength="409600"

       executionTimeoutInSeconds="300"/>

 </system.web>

</configuration>

With above setting, you can send 400MB of data with maximum time of 300 seconds. After that time, your execution will get stopped as TimeOut.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM