locked
How to define a web service in User Control and consume it there?? RRS feed

  • Question

  • User1402743388 posted

    Hi,

    As I am building web user controls for my application, I am trying to define the web services in the code behind which is not a problem but I donot know how to define the ajax service call since the control could be in any page. The web method is going to be consumed from the same control.

    The key here is that WebService definition has to be within the WebUserControl Code behind. so  MyControl.ascx has the call to a webservice defined in MyControl.asscx.cs. 

    Any ideas?

    Thanks

    Thursday, September 26, 2013 1:09 PM

Answers

  • User-742633084 posted

    Hi Theguzu,

    So you have some ASP.NET webservice which will be called from some ASCX usercontrols (via client-side AJAX script) in web application, correct?

    If so, you can just make sure your webservice will have a common and fixed contract ( the webmethods available) and then your ASCX usercontrols just need to embed the certain javascript functions which calls the webservice  inside its ascx template. Also, since the webservice should be within the same web application with the ascx usercontrol's hosting pages, it is  easily to locate the webservice via absolute or relative paths.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 27, 2013 2:25 AM
  • User-742633084 posted

    Thanks for further clarify Theguzu,

    Then, I'm afraid ascx usercontrol cannot directly expose any kind of webservice or service method (callable from page's client-side script). If you want to expose some service method which can be called from page/usercontrol's client-side script, you need to either add a separate webservice/httphandler or add static page methods in the hosting aspx page (which contain the user control).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 2, 2013 10:41 PM

All replies

  • User-742633084 posted

    Hi Theguzu,

    So you have some ASP.NET webservice which will be called from some ASCX usercontrols (via client-side AJAX script) in web application, correct?

    If so, you can just make sure your webservice will have a common and fixed contract ( the webmethods available) and then your ASCX usercontrols just need to embed the certain javascript functions which calls the webservice  inside its ascx template. Also, since the webservice should be within the same web application with the ascx usercontrol's hosting pages, it is  easily to locate the webservice via absolute or relative paths.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 27, 2013 2:25 AM
  • User1402743388 posted

    Thank you for the reply. The key here is that WebService definition has to be within the WebUserControl Code behind. so  MyControl.ascx has the call to a webservice defined in MyControl.asscx.cs. Any ideas is greatly appreciated.

    Friday, September 27, 2013 8:02 AM
  • User-742633084 posted

    Thanks for further clarify Theguzu,

    Then, I'm afraid ascx usercontrol cannot directly expose any kind of webservice or service method (callable from page's client-side script). If you want to expose some service method which can be called from page/usercontrol's client-side script, you need to either add a separate webservice/httphandler or add static page methods in the hosting aspx page (which contain the user control).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 2, 2013 10:41 PM