I can't seem to figure out why I am unable to call a webservice. What could I be missing? @@
I'm attempting to follow the instructions provided here: How to call an ASP.Net Web Service in javascript
Below are my codes, but they are failing to work.
This is the webservice code snippet:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
namespace Library
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService()]
public class ReleaseSessionObject : System.Web.Services.WebService
{
[WebMethod]
public string HelloWord()
{
return "Hellow Word!";
}
}
}
And this is my ASP.NET page code snippet:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm6.aspx.cs" Inherits="Library.WebForm6" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<script src="ReleaseSessionObject.asmx" type="text/javascript"></script>
<script type="text/javascript">
function HelloWorld() {
try {
var a = Library.ReleaseSessionObject.HelloWorld();
alert(a);
}
catch (err) {
alert(err.Message);
}
};
</script>
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/ReleaseSessionObject.asmx" />
</Services>
</asp:ScriptManager>
<input type="button" onclick="HelloWorld();" value="Click This" />
</div>
</form>
</body>
</html>
Both the ASP.NET page and Service files are located in the same folder.
However, when clicking on the button, it returns: undefined