【问题标题】:WebMethod not working when returning relatively large string返回相对较大的字符串时WebMethod不起作用
【发布时间】:2012-01-17 02:01:46
【问题描述】:

我在 Visual Studio 2008 中将 Virtual Basic 与 ASP.NET 一起使用。我正在使用 Web 方法在服务器与客户端之间进行通信。可以查询和返回少量数据,但是当我尝试获取相对大量的数据时,它返回给我一个Server 500错误。我的数据是 226561 个字符长,所以它不是那么大,但它比我的其他工作测试集(大约 10k 个字符长)要大。

JavaScript:

    PageMethods.my_func("context", success);
    function success(result, userContext, methodName) {
        alert("success!");
    }

虚拟基本代码失败:

<System.Web.Services.WebMethod()> _
Public Shared Function my_func(ByVal context As String) As IEnumerable
    var result = "..."  '200k characters long
    Return result
End Function

成功的虚拟基础代码:

<System.Web.Services.WebMethod()> _
Public Shared Function my_func(ByVal context As String) As IEnumerable
    var result = "..."  '10k characters long
    Return result
End Function

有什么我可以改变来增加 WebMethod 返回的字符串长度限制吗?是否有长度限制或者是我看不到的其他问题?

【问题讨论】:

  • 您为什么将string 作为IEnumerable 返回?
  • 教程告诉我这样做。在返回结果之前,我实际上做了自己的序列化。这是多余的吗?
  • 如果您对字符串执行序列化而不是将方法声明为简单地返回string,而不是IEnumerable

标签: javascript asp.net vb.net


【解决方案1】:

我认为您的问题可能与maxJsonLength 属性有关(更多信息here)。

您可以在 web.config 中调整此设置:

【讨论】:

  • @YongkeBillYu:多年来我们因相同或相似的问题而陷入困境。
猜你喜欢
  • 2011-09-03
  • 1970-01-01
  • 1970-01-01
  • 2018-06-06
  • 2016-12-18
  • 1970-01-01
  • 2011-09-20
相关资源
最近更新 更多