Problem You get following error when you use javascript to call Web Methods defined in Web Service file(ASMX). This usually happens when you are using ASP.Net AJAX framework. The server method failed with the following error: System.InvalidOperationException-- Maximum length exceeded. Everything works fine until the web service returns a larger number of objects. Solution Go to your Web.Config file. Add sections as shown below. In jsonSerialization section set maxJsonLength="500000". If you still get this error, increase maxJsonLength.
=========================Web.Config================================================= type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"> type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere" /> type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />
type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" /> . Add following section outside section. This change in Web.Config file should resolve this error. Cause When you call ASP.Net Web Methods from javascript, it uses serialization and de-serialization of returned objects. Serialization converts .Net objects to XML format.When this XML data length exceeds default limit of serialization, ASP.Net throws this error. To prevent this error you should make sure that returned object does not generate large XML data. If it's not possible to decrease data, you can use above solution to fix it. But this may slow down ASP.Net application as it has to transmit so much of data for each call. Comments/Questions | nice it help me => yogesh (Monday 13-Oct-08 04:27 AM) | | | | {mos_fb_discuss:15}
|