jQuery web service invocation 411 Length required Error

I had a jQuery web service invocation of the form:

        $.ajax({
            type: "POST",
            url: "/ws/MyServices.asmx/MyOpWithNoParam",
            contentType: "application/json; charset=utf-8",
            success: function(msg) {
                    //do something
            },
            error: function(xhr, ajaxOptions, thrownError) {
                    ///handle error
            }
        });  

When deployed on the web server (Windows 2008 Server, IIS7) it failed miserably at runtime with error:  HTTP Error 411 Length required

I tried changing to GET transport method with no luck, what fixed this issue was adding one dummy string parameter to the webservice, and then adding the data field in the ajax invocation.

        $.ajax({
            type: "POST",
            url: "/ws/MyServices.asmx/MyOpWithONEParam",
            data: "{ data:'test' }",
            contentType: "application/json; charset=utf-8",
            success: function(msg) {
   
            },
            error: function(xhr, ajaxOptions, thrownError) {

            }
        });

 hope this helps

No Comments