MyService.svc
MyService.cs
using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
[ServiceContract(Namespace = "PankajNM")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MyService
{
[OperationContract]
public void DoWork()
{
// Add your operation implementation here
return;
}
[OperationContract]
public string GetUser(string uname)
{
return "Hello " + uname;
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>Create AJAX-enabled WCF Service</title>
<script language="javascript" type="text/javascript">
function btnCallWCF_onclick() {
var GetTo= new PankajNM.MyService();
GetTo.GetUser($get("txtUNm").value, OnComplete, OnError);
}
function OnGreetingComplete(result) {
$get("dispGuser").innerHTML = result;
}
function OnError(result) {
alert(result.get_message());
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/MyService.svc" />
</Services>
</asp:ScriptManager>
<input id="btnCallWCF" type="button" value="GetUser" onclick="return btnCallWCF_onclick()" />
<input id="txtUNm" type="text" />
<div id="dispGuser">
</div>
</div>
</form>
</body>
</html>
MyService.cs
using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
[ServiceContract(Namespace = "PankajNM")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MyService
{
[OperationContract]
public void DoWork()
{
// Add your operation implementation here
return;
}
[OperationContract]
public string GetUser(string uname)
{
return "Hello " + uname;
}
}
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>Create AJAX-enabled WCF Service</title>
<script language="javascript" type="text/javascript">
function btnCallWCF_onclick() {
var GetTo= new PankajNM.MyService();
GetTo.GetUser($get("txtUNm").value, OnComplete, OnError);
}
function OnGreetingComplete(result) {
$get("dispGuser").innerHTML = result;
}
function OnError(result) {
alert(result.get_message());
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/MyService.svc" />
</Services>
</asp:ScriptManager>
<input id="btnCallWCF" type="button" value="GetUser" onclick="return btnCallWCF_onclick()" />
<input id="txtUNm" type="text" />
<div id="dispGuser">
</div>
</div>
</form>
</body>
</html>