I am making a jQuery AJAX call to a back-end WebMethod in an aspx.cs page. I am getting an error in the .NET JSON serialization. As such, I am looking for ways to either fix the error or avoid using JSON (the only return format for WebMethods):
Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property
The associated StackTrace is :
at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat)\r\n at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary'2 rawParams)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)
The backend code is as follows (note: result
is, in actuality about 110k of a control rendered to a string):
[WebMethod]
public static string GetContactListControl()
{
try
{
var result = "Hello World!"
return result;
}
catch (Exception e){
Logging.LogException(e);
return "Exception Thrown";
}
}
And I am never hitting the catch
block, which to me shows that this issue is outside of my code.
I found a fix involving changing the web.config by inserting the following block, but it is not working:
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="123456"></jsonSerialization>
</webServices>
</scripting>
</system.web.extensions>
Project is .NET 3.5.
Thank you for any ideas and suggestions!