0

I am using an MS Virtual Earth AJAX control to plot custom boundaries on a map in my ASP.Net 3.5 site. I have a WCF service which I call from ASP.Net to return the points I need to plot. In one instance, I need to plot ~40,000 points.

I get the following error any time the amount of points (rows returned from WCF service) I need to plot are over 25,000.

Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.

I tried modifying the maxJsonLength property in my web.config to 2147483647 but changing this value has no effect. No matter what I set the value to, I always get an error when I try to plot more than 25,000 points. I even tried setting it to "ABC" and my site still worked when my WCF service returned less than 25,000 records.

I verified that I don't have the maxJsonLength property in my machine.config file.

Below is an excerpt from my web.config file:

*<configuration>
      <configSections>
            <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
                  <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
                        <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
                        <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
                              <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
                              <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
                              <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
                              <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/></sectionGroup></sectionGroup></sectionGroup></configSections><appSettings/>
      <connectionStrings/>
      <system.web.extensions>
            <scripting>
                  <webServices>
                        <jsonSerialization maxJsonLength="2147483647"/>
                  </webServices>
            </scripting>
      </system.web.extensions>*

Any idea my changes to the maxJsonLength property aren't being recognized?

Ramesh Rajendran
  • 37,412
  • 45
  • 153
  • 234
  • See http://stackoverflow.com/questions/1151987/can-i-set-an-unlimited-length-for-maxjsonlength-in-web-config – Nik Dec 07 '14 at 16:07

2 Answers2

1

You can try to change it from WCF service

var jsonResult = Json(data, JsonRequestBehavior.AllowGet);
  jsonResult.MaxJsonLength = int.MaxValue;
  return jsonResult;
Nico
  • 31
  • 2
0

Additionally, add following key to appSettings:

<appSettings>
    <add key="aspnet:MaxJsonDeserializerMembers" value="2147483647" />
    ...
</appSettings>

At least in Mvc, this setting is enough to solve this problem.

Varun K
  • 3,593
  • 2
  • 25
  • 26