I am trying to call WebMethodfrom JavaScript. So far I:
EMSWebService.asmx:
namespace EMSApplication.Web.WebServices
{
/// <summary>
/// Holds the Webservice methods of EMSApplication
</summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class EMSWebService : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
}
On the aspx page, I added the following:
<asp:ScriptManager ID="ScriptManager" runat="server">
<Services>
<asp:ServiceReference Path="~/WebServices/EMSWebService.asmx" />
</Services>
</asp:ScriptManager>
<input onclick="callWebMethod();" id="btn" type="button" value="Click Me" />
And JavaScript:
<script type="text/javascript">
function callWebMethod() {
EMSApplication.Web.WebServices.EMSWebService.HelloWorld(OnComplete, OnError);
}
function OnComplete(result) {
alert(result);
}
function OnError(result) {
alert(result.get_message());
}
</script>
But the method does not execute. I get the following JavaScript error:
EMSApplication is undefined.
Is there anything I can't see? Do I need to do a different configuration?
The structure of the project is shown below:

JavaScript and components are located in Login.aspx.
Is there a url value [WebService(Namespace = "http://tempuri.org/")]
Edit:
I also tried this with jQuery and modified the aspx page as:
$(document).ready(function () {
$("#btn").click(function () {
$.ajax({
type: "POST",
url: "../WebServices/EMSWebService.asmx/HelloWorld",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert(response.d);
},
failure: function (msg) {
alert(msg.d);
}
});
return true;
});
});
I wrote System.Diagnostics.Debug.WriteLine("Hello World");inside WebMethod, it does what it prints "Hello World" in the Visual Studio output window, but I do not get a warning message.