从web服务检索大量数据时,代码失败

本文关键字:代码 失败 数据 web 服务 检索 | 更新日期: 2023-09-27 18:15:17

我有一个web服务返回一些Json的东西到我的iPhone应用程序,它工作得很好,只要返回的数据量有点小,但如果我增加返回的数据量的应用程序是无法处理它。有没有办法解决这个问题,不可能是218KB的限制…?

这是我当前的代码:

[WebService(Namespace = "http://mydomain.com/webservicesfeed")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]
    public class feedPerson : System.Web.Services.WebService
    {
        [WebMethod(BufferResponse = false)]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public List<Person> getData()
        {
            List<Person> res = new List<Person>();
                res = searchPerson("32.8762", "13.1875");
            return res;
        }
    }

如果我调用web服务抛出jQuery,它也失败了,所以我想问题是在web服务。

这是我用来尝试的jQuery代码:

 <script type="text/javascript">
     $.ajax({
         type: "POST",
         contentType: "application/json; charset=utf-8;",
         url: "http://mydomain.com/feedPerson.asmx/getData",
         dataType: "json",
         success: function (data, textStatus, jqXHR) {
             alert(data.d[0]);
         },
         error: function (jqXHR, textStatus, errorThrown) {
             alert("Fail");
         }
     });
    </script>

如何解决这个问题?

从web服务检索大量数据时,代码失败

捕捉到错误给了我以下信息:"字符串的长度超过了maxJsonLength属性上设置的值"。

然后我发现这篇文章:我可以在web.config中设置maxJsonLength的无限长度吗?

并在my web.config中设置以下内容:

<system.web.extensions>
    <scripting>
        <webServices>
            <jsonSerialization maxJsonLength="2147483647"/>
        </webServices>
    </scripting>
</system.web.extensions>

问题已解决

http://msdn.microsoft.com/en-us/library/aa528822.aspx默认有限制。

<>之前& lt; configuration>& lt; system.web>& lt; httpRuntime maxMessageLength ="409600";executionTimeoutInSeconds ="300"/比;& lt;/system.web>& lt;/configuration>