1

I have a web service returning some Json stuff to my iPhone application and it works fine as long as the amount of returned data is kind of small but if I increase the amount of data that is returned the application is not able to process it. Is there a way to solve this, can't possibly be a limit of 218KB...?

This is my current code:

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

If I call the web service throw jQuery it also fails so I guess the problem is at the web service..

This is the jQuery code I used to try it out:

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

How could this be solved?

Mikael
  • 5,429
  • 5
  • 30
  • 38
  • Have you put a break point in your web service? Does it get called? How many persons does searchPerson return? Can you do a get request to the service with a web browser to see what you get back? Where does your 218k number come from? – Darryl Braaten Nov 22 '11 at 00:12
  • @DarrylBraaten No breakpoint, it gets called, 100 persons is ok but 150 is not, if I visit http://mydomain.com/persons.asmx/getData through the browser it returns a xml file containing all persons (no problem with 150 persons), 218k is the size of the returned xml-file. – Mikael Nov 22 '11 at 00:26
  • What's the failure? Is there an error or exception thrown by either the server or the client? – Philipp Schmid Nov 22 '11 at 00:29
  • @PhilippSchmid I guess it is the server as the response is the same for both the iPhone app and jquery. request: {"Message":"There was an error processing the request.","StackTrace":"","ExceptionType":""} – Mikael Nov 22 '11 at 00:33
  • Do you have access to the server? Do you see anything in the event log that would tell you what's going wrong? Or better, either have a try/catch block around your server code or attach a debugger and let it tell you what the exception is. Once you know what's going wrong you should be able to fix the issue (code or configuration). – Philipp Schmid Nov 22 '11 at 00:44
  • have you try to set ? – shenhengbin Nov 22 '11 at 01:18
  • @PhilippSchmid This actually helped me find the error: "The length of the string exceeds the value set on the maxJsonLength property" Will post the answer so that it hopefully helps someone else in the future. Thanks! – Mikael Nov 22 '11 at 01:41

2 Answers2

2

Catching the error gave me the following information: "The length of the string exceeds the value set on the maxJsonLength property".

Then I found this post: Can I set an unlimited length for maxJsonLength in web.config?

and by setting the following in my web.config:

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

The issue was solved.

Community
  • 1
  • 1
Mikael
  • 5,429
  • 5
  • 30
  • 38
1

http://msdn.microsoft.com/en-us/library/aa528822.aspx There are limits by default.

<configuration>
  <system.web>
  <httpRuntime maxMessageLength="409600"
    executionTimeoutInSeconds="300"/>
  </system.web>
</configuration>
Adam Tuliper
  • 29,982
  • 4
  • 53
  • 71