locked
Ajax WebMethod Call RRS feed

  • Question

  • User-305496339 posted

    I am using JQuery to make an Ajax  call to a WebMethod. What file .asmx, aspx, or aspx.cs should I declare my WebMethod? Also how do I debug or step through my WebMethod? I notice that I cannot put a breakpoint in the WebMethod or maybe I am doing something wrong. Thanks !!! 

    Friday, June 9, 2017 1:55 PM

Answers

  • User475983607 posted

    rkrex

    I am using JQuery to make an Ajax  call to a WebMethod. What file .asmx, aspx, or aspx.cs should I declare my WebMethod? 

    If you are building an ASP Web Forms application use a static web method in the page class.

    ASMX is a SOAP service and IMHO should be used as such not invoked via AJAX.  However, it is fairly easy to invoke ASMX via AJAX. 

    rkrex

    Also how do I debug or step through my WebMethod? I notice that I cannot put a breakpoint in the WebMethod or maybe I am doing something wrong.

    You should be able to debug a web method.  Are you sure the web method is being hit?  Since you are using AJAX, there could be a client side error.  Open developer tools by pressing F12 in your browser.  Open the console tab.  Try invoking the service again and look for errors.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 9, 2017 2:11 PM
  • User632428103 posted

    Hello all,

    @rkrex => read these article :

    - web method in asp net page :

    https://www.aspsnippets.com/Articles/Calling-ASPNet-WebMethod-using-jQuery-AJAX.aspx

    - web method in a asmx web service

    https://www.aspsnippets.com/Articles/Call-Consume-Web-Service-ASMX-using-jQuery-AJAX-in-ASPNet.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 9, 2017 2:43 PM
  • User-1838255255 posted

    Hi rkrex,

    According to your description, I try give a explanation of your issues. Please check:

    I am using JQuery to make an Ajax  call to a WebMethod. What file .asmx, aspx, or aspx.cs should I declare my WebMethod?

    As far as I know, asmx  is an abbreviation for Active Server Method File, a file with the ASMX file extension is an ASP.NET Web Service Source file.

    It provides the web server, then use http to call it, return data.

    ASPX files usually will have the UI and will which is usually HTML tags, some ASP.NET server control embed code (which ultimately produce some HTML markups). ASPX.CS file (usually called the codebehind) will have server-side coding in C#.

    Also how do I debug or step through my WebMethod? I notice that I cannot put a breakpoint in the WebMethod or maybe I am doing something wrong. Thanks !!! 

    I think add a breakpoint to debug code is ok, so I am not clear the meaning of "cannot put a breakpoint in the webmethod" that you said, can't be involved or other phenomenon?

    I hope you could give us a detailed description of your issue, this will better help you?

    Also you could through Browser-F12-console panel to check if meet some error.

    Finally, I hope you could tell us what error or issue you meet that why you debug your code.

    Best Regards,

    Eric Du

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 12, 2017 9:07 AM

All replies

  • User475983607 posted

    rkrex

    I am using JQuery to make an Ajax  call to a WebMethod. What file .asmx, aspx, or aspx.cs should I declare my WebMethod? 

    If you are building an ASP Web Forms application use a static web method in the page class.

    ASMX is a SOAP service and IMHO should be used as such not invoked via AJAX.  However, it is fairly easy to invoke ASMX via AJAX. 

    rkrex

    Also how do I debug or step through my WebMethod? I notice that I cannot put a breakpoint in the WebMethod or maybe I am doing something wrong.

    You should be able to debug a web method.  Are you sure the web method is being hit?  Since you are using AJAX, there could be a client side error.  Open developer tools by pressing F12 in your browser.  Open the console tab.  Try invoking the service again and look for errors.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 9, 2017 2:11 PM
  • User632428103 posted

    Hello all,

    @rkrex => read these article :

    - web method in asp net page :

    https://www.aspsnippets.com/Articles/Calling-ASPNet-WebMethod-using-jQuery-AJAX.aspx

    - web method in a asmx web service

    https://www.aspsnippets.com/Articles/Call-Consume-Web-Service-ASMX-using-jQuery-AJAX-in-ASPNet.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 9, 2017 2:43 PM
  • User-1838255255 posted

    Hi rkrex,

    According to your description, I try give a explanation of your issues. Please check:

    I am using JQuery to make an Ajax  call to a WebMethod. What file .asmx, aspx, or aspx.cs should I declare my WebMethod?

    As far as I know, asmx  is an abbreviation for Active Server Method File, a file with the ASMX file extension is an ASP.NET Web Service Source file.

    It provides the web server, then use http to call it, return data.

    ASPX files usually will have the UI and will which is usually HTML tags, some ASP.NET server control embed code (which ultimately produce some HTML markups). ASPX.CS file (usually called the codebehind) will have server-side coding in C#.

    Also how do I debug or step through my WebMethod? I notice that I cannot put a breakpoint in the WebMethod or maybe I am doing something wrong. Thanks !!! 

    I think add a breakpoint to debug code is ok, so I am not clear the meaning of "cannot put a breakpoint in the webmethod" that you said, can't be involved or other phenomenon?

    I hope you could give us a detailed description of your issue, this will better help you?

    Also you could through Browser-F12-console panel to check if meet some error.

    Finally, I hope you could tell us what error or issue you meet that why you debug your code.

    Best Regards,

    Eric Du

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 12, 2017 9:07 AM