简体   繁体   English

ajax调用-在asmx webmethod中返回大json字符串时出现outofmemory异常

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

Exception of type 'System.OutOfMemoryException' was thrown: 引发了类型为'System.OutOfMemoryException'的异常:

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) 在System.Web.Util.HttpEncoder.JavaScriptStringEncode(字符串值)在System.Web.HttpUtility.JavaScriptStringEncode(字符串值,布尔值addDoubleQuotes)在System.Web.Script.Serialization.JavaScriptSerializer中。 System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o,StringBuilder sb,Int32深度,Hashtable objectsInUse,SerializationFormat serializationFormat,MemberInfo currentMember)上的SerializeString(String input,StringBuilder sb)
at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) 在System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(对象o,StringBuilder sb,Int32深度,哈希表objectsInUse,SerializationFormat serializationFormat,MemberInfo currentMember)
at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat) 在System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj,StringBuilder输出,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) 在System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext上下文,WebServiceMethodData methodData,IDictionary`2 rawParams)处的System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj,SerializationFormat serializationFormat)
at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData) 在System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext上下文,WebServiceMethodData methodData)

json string that returned is big(more than 5MB), what are the solution for this problem? 返回的json字符串很大(超过5MB),该问题的解决方案是什么?

By default, it is possible to send or receive 4MB of data(Maximum). 默认情况下,可以发送或接收4MB数据(最大)。 If you want to send more than that, you have to change the maxMessageLength in your web.config file like below. 如果您想发送更多内容,则必须在web.config文件中更改maxMessageLength,如下所示。

 <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. 通过上述设置,您可以发送300 MB的最大时间的400 MB的数据。 After that time, your execution will get stopped as TimeOut. 在那之后,您的执行将以TimeOut停止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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