Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3360018
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:56:33+00:00 2026-05-18T02:56:33+00:00

[NOTE:I am really looking for some good debugging techniques here. Perhaps some tricks or

  • 0

[NOTE:I am really looking for some good debugging techniques here. Perhaps some tricks or ways to simplify things of which I am unaware.]

I am using the technique of calling [WebMethods] defined in an ASPX page from JQuery as mentioned here and here. It seems to be an increasingly common method.

I’ve been using it for a while and, in general, it works great. But while developing it is pretty fragile. Any incorrect parameter will result in a really vague, non-specific, error message. For instance, if I have a fairly complex web method defined as:

[WebMethod]
public static string SaveComplexRecord(int recID, GeneralData general, SomeObject data, SomeOtherObject moreData)
{
   //do a bunch of stuff with that data
}

And GeneralData, SomeObject, and SomeOtherObject all have a mix of various types of parameters (strings, ints, bools, datetimes.) It is very likely, especially during initial development, that I will build the JSON on the client side incorrectly. Perhaps 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
    }
};

Which will result in an error because the name of the third parameter is moreData, not moredata. And that’s just an example, there could be any of a hundred other subtle typo-style errors.

If I were calling this method from C# the compiler would give me an error message something like “No overloaded method of SaveComplexRecord takes three parameters.” or some other helpful message that points you in the right direction.

So… is there a way of getting ASP.Net to produce better error messages here?

Or is there some utility that will automatically build the JSON parameter structure of a [WebMethod] call? (just like you can automatically get the WSDL of a web service)

…or any other technique that I may be missing?

And for completeness here is how 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)
        {
            //do something on success
        },
        error: function(XMLHttpRequest, textStatus, errorThrown)
        {
            alert("ERROR status:" + textStatus + " error:" + errorThrown);
        }

    });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T02:56:34+00:00Added an answer on May 18, 2026 at 2:56 am

    Or is there some utility that will automatically build the JSON parameter structure of a [WebMethod] call? (just like you can automatically get the WSDL of a web service)

    Yes! The ASP.Net AJAX framework can do this! You could get the framework to generate client side proxy classes for GeneralData, SomeObject and SomeOtherObject classes using the ‘GenerateScriptType’ attribute on a web service class.
    See understanding asp net ajax web servcies for a very good article about the subject.

    [Unfortunately, AFAIAA, the GenerateScriptType has no effect when applied to the Page class where your page method is defined – so you will have to add an .asmx purely to get the proxy generation.]

    You could perhaps use these classes to build up the data structure that you then JSON stringify when you call .ajax? [One of (the very few) things I really like about the MS AJAX framework is the client side proxy generation: it really does make calling web services and page methods very easy. Having said that, I too am moving towards using jQuery in preference to MS AJAX.]

    Or alternatively…
    Your problem is really that the de-serialisation of the JSON data into the arguments of your page method is done transparently by the framework (which in most cases is a good thing) but when it goes wrong, the feedback you get is less-than-helpful. If you want to trap de-serialisation problems then I think you have to take control of the serialisation either by using custom JSON converters (see here) or by using the rather inelegant sledgehammer approach of having your method accept a string and de serializing the JSN yourself in the method – which is trivial with anyone of the numerous JSON libs out there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

[Meta-note:] I was browsing the question page, getting really tired of DIVS vs Tables
Note that I am not asking which to choose (MVC or MVP), but rather
Note The question below was asked in 2008 about some code from 2003. As
I'm really wanting to learn assembly. I'm pretty good at c/c++, but want a
my robotics lab is looking for programmers to work on some projects we have
I'm looking for a Git alternatives to svn info. Today I added some information
NOTE: XMLIgnore is NOT the answer! OK, so following on from my question on
Note: This was posted when I was starting out C#. With 2014 knowledge, I
NOTE: I am not set on using VI, it is just the first thing
Note: Originally this question was asked for PostgreSQL, however, the answer applies to almost

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.