的WebMethod

编程入门 行业动态 更新时间:2024-10-28 14:33:56
本文介绍了的WebMethod - JSON序列化错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想提出一个jQuery AJAX调用在aspx.cs页后端的WebMethod。我收到的.NET JSON序列化的错误。因此,我在寻找各种方法来解决任何错误或避免使用JSON(为的WebMethods只返回格式):

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):

使用JSON JavaScriptSerializer序列化和反序列化过程中的错误。字符串的长度超过上maxJsonLength属性设置的值

相关联的堆栈跟踪是: 在System.Web.Script.Serialization.JavaScriptSerializer.Serialize(obj对象,StringBuilder的输出,SerializationFormat serializationFormat)\ r \ n将在System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext的背景下,WebServiceMethodData methodData ,IDictionary'2 rawParams)\ r \ n将在System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext的背景下,WebServiceMethodData methodData)

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)

后端code是如下(注:结果是,在现实中大概呈现为一个字符串控制的110K):

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"; } }

和我从来没有碰到抓块,这对我表明,这个问题是我的code之外。

And I am never hitting the catch block, which to me shows that this issue is outside of my code.

我发现涉及改变web.config中插入以下块的修复程序,但它不工作:

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是.NET 3.5。

Project is .NET 3.5.

感谢您的任何意见和建议!

Thank you for any ideas and suggestions!

推荐答案

在maxJsonLength财产的配置必须设置在web.config中。为了让被IIS允许这种配置,下面&LT; sectionGroup&GT; 必须包含的&LT内部; configSections&GT; :

Configuration of the maxJsonLength property must be setup in the web.config. In order to allow this configuration to be permitted by IIS, the following <sectionGroup> must be included inside of <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>

更多推荐

的WebMethod

本文发布于:2023-11-26 19:42:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634939.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:WebMethod

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!