Tried to create a sample app which will call asp.net webservice using ajax. Here is the code:
Web Service--------
namespace MyWebService
{
/// <summary>
/// Summary description for MyService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class MyServiceClass : System.Web.Services.WebService
{
[System.Web.Script.Services.ScriptMethod]
[WebMethod]
public string MyNewMethod()
{
return "Hello Deep!";
}
}
}
ASP.NET AJAX Call-----------------
This type of program seems to be a very common sample on internet,
but I am unable to reach the service, and getting error message at runtime saying :
"<title>No web service found at: /MyServiceClass.asmx.</title>"
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<style type="text/css">
body { font: 11pt Trebuchet MS;
padding-top: 72px;
text-align: center }
.text { font: 8pt Trebuchet MS }
</style>
<script type="text/javascript">
function InvokeService() {
MyWebService.MyServiceClass.MyNewMethod(OnSucceed);
}
function OnSucceed(result){
var element = Document.getElementById("Label1");
Label1.innerHTML = "result"
}
</script>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="http://localhost:14924/MyServiceClass.asmx"/>
</Services>
</asp:ScriptManager>
</div>
<asp:Button ID="Button1" runat="server" Text="MyButton"
OnClientClick="InvokeService()"/>
<asp:Label ID="Label1" runat="server" Text="MyLabel"></asp:Label>
</form>
</body>
</html>