I am trying to understand how the following snippet of code works. The person who designed it is not around to explain to me how its working (also why he/she didn't use ajax calls). I've asked few co-workers and they seem to not have the proper explanation for me to understand how the JavaScript was able to access webmethod directly. I am hoping my example is good enough to at least get a reasonable explanation since I can't post the original code.
Web Service
namespace ClientName.Version.Services
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class ClassName : System.Web.Service.WebService
{
[WebMethod(EnableSession = true)]
public List<ReturnData> WebMethod(string param1)
{
.
.
.
}
}
}
Javscript Call
(function(){
var param = "Broken down calls";
.
.
.
ClientName.Version.Services.ClassName.WebMethod(
param, function(dataReturnedFromService){
if(dataReturnedFromService != null){
//process data and append to html
}
}
);
})();
Edited: After @matt pointed me to the right spot, on top of his response if anyone cares to now more http://msdn.microsoft.com/en-us/library/bb398998(v=vs.100).aspx
or google
"Exposing Web Services to Client Script" for more.