I have a .Net Web service (.asmx) which will return a Json string to my client. However, some of my data is really large and I get this error occasionally.
The length of the string exceeds the value set on the maxJsonLength property.
I've changed the maxJsonLength property to 2147483644, but it still doesn't work. Please help... Thank you.
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483644"/>
</webServices>
</scripting>
</system.web.extensions>
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public void GetData(string login)
{
// throw an error on this line...
string result = new JavaScriptSerializer().Serialize(service.GetData(login));
Context.Response.Write(result);
}
Thanks to Ed Gibbs and @NextInLine 's suggestion. I did the fix as below and it work like a charm now. I also removed the "system.web.extensions" portion away from my web.config
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public void GetData(string login)
{
// when the amount of data return is huge
var serializer = new JavaScriptSerializer();
// we need to do this.
serializer.MaxJsonLength = Int32.MaxValue;
var result = serializer.Serialize(service.GetData(login));
Context.Response.Write(result);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With