[NOTE: I'm really looking for good debugging methods here. Perhaps some tricks or ways to simplify things that I don't know about.]
I use the [WebMethods] call method defined on the ASPX page from jQuery, as mentioned here and here . This seems to be an increasingly common method.
I used it for a while, and overall it works great. But in development, it is rather fragile. Any incorrect parameter will result in a truly indefinite, non-specific error message. For example, if I have a rather sophisticated web method defined as:
[WebMethod] public static string SaveComplexRecord(int recID, GeneralData general, SomeObject data, SomeOtherObject moreData) {
And in GeneralData, SomeObject and SomeOtherObject there is a combination of different types of parameters (strings, ints, bools, datetimes.) It is very likely, especially during the initial development, that I will incorrectly create JSON on the client side, Maybe I will do this:
var data = { recID: curID, general: { a: aValue, b: bValue, c: cValue }, data: { d: dValue, e: eValue, f: fValue }, moredata: { g: gValue, h: hValue, i: iValue } };
This will result in an error, because the name of the third parameter is more than Data, not moredata. And this is just an example, maybe any of one hundred other subtle mistakes in the style of typos.
If I called this method from C #, the compiler would give me an error message like "No overloaded method of SaveComplexRecord takes three parameters." or some other useful message pointing you in the right direction.
So ... is there a way to get ASP.Net to create better error messages here?
Or is there any utility that will automatically build a JSON parameter structure for calling [WebMethod]? (just like you can automatically get WSDL web services)
... or any other method I might lose?
And for completeness, here I call these WebMethods from jQuery:
var jsondata = $.toJSON(data); $.ajax({ type: "POST", url: "MyWebPage.aspx/SaveComplexRecord", data: jsondata, contentType: "application/json; charset=utf-8", dataType: "json", beforeSend: function(xhr) { xhr.setRequestHeader("Content-type", "application/json; charset=utf-8"); }, success: function(msg) {