0

My ASP.NET 4.5 .asmx web service (part of a web forms project, not separated) returns an xml string whenever the user double-clicks on a table row so the details for that row can be retrieved from the database.

This, in and of itself, works fine.

In situations however, where the response is somewhat longer (around 200k, 300k char count from what I can see), the web page will throw a js alert popup (saying "Error") and I'll see a 500 Internal Server Error in the Chrome console, no further details. However, when I go to the web method url and enter the arguments manually, I'll get an immediate and complete xml string in response without issues.

I'm using the following (synchronous) js/ajax to call the web method:

function GetDetailsFromTableRow(userID, country, rowName) {
    var url = "http://MyServer/MyWebService.asmx/MyWebMethod",
        result = '';

    $.ajax({
        type: "POST",
        async: false,
        url: url,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: JSON.stringify({
            'userID': userID,
            'country': country,
            'rowName': rowName
        }),
        success: function (response) {
            result = response.d;
        },
        error: function (x, t, m) {
            if (t === "timeout") {
                alert('timeout!');
            }
            else {
                alert(t); //<- this gets thrown apparently
            }
        }
    });

    return result;
}

From this js you can ascertain that this function is, in fact, NOT throwing a timeout so I'm fairly certain I can eliminate that.

Furthermore, I would assume that I needn't chunk the response myself for data that is merely a few hundred kilobytes but still: I might be wrong.

I'm also quite aware that the better way to call web methods is asynchronously, but I'm succeeding in calling other (substantial) data already (both in async and sync ways) so I'm looking for an answer to the question why this is not working for responses over a certain size (I have responses that are 80kB and some that are 200+kB, the former work, the latter don't) because I'm obviously not understanding some parts of the whole story.

For completeness: an async=true call to the web service causes the exact same behavior.

Wim Ombelets
  • 5,097
  • 3
  • 39
  • 55

1 Answers1

0

debugging the js in IE yielded following error:

Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property

as mentioned in this answer (and corrective comments), adding the following entries to the web.config increased the maxJsonLength value to int.MaxValue:

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

subsequent tests are all successful. Issue resolved.

Community
  • 1
  • 1
Wim Ombelets
  • 5,097
  • 3
  • 39
  • 55