<%@ WebService Language="C#" Class="HRService" %>
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
[ScriptService]
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class HRService : System.Web.Services.WebService {
[ScriptMethod]
[WebMethod]
public int GetEmployeeCount(string department)
{
System.Threading.Thread.Sleep(2000);
return HumanResources.GetEmployeeCount(department);
}
}
moshik.salem
Member
34 Points
124 Posts
server-centric vs. client-centric approaches question
Jul 27, 2012 09:35 AM|LINK
hi,
which approach consider the best to use, the client-centric ajax approach? or the server-centric ajax approach?
Mudasir.Khan
All-Star
15346 Points
3142 Posts
Re: server-centric vs. client-centric approaches question
Jul 27, 2012 10:42 AM|LINK
may i request you explain the question in bit more details please ?
HTTP Requests are alway Client to Server and Ajax does follow the same but it just that does it Async
moshik.salem
Member
34 Points
124 Posts
Re: server-centric vs. client-centric approaches question
Jul 27, 2012 11:23 AM|LINK
like this:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ClientCentric.aspx.cs" Inherits="ClientCentric" %> <!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>Client-Centric Example</title> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> <Services> <asp:ServiceReference Path="HRService.asmx" /> </Services> </asp:ScriptManager> <h2>Employee Lookup</h2> <div> <select id="Departments" size="5"> <option value="Engineering">Engineering</option> <option value="HR">Human Resources</option> <option value="Sales">Sales</option> <option value="Marketing">Marketing</option> </select> </div> <br /> <div> <span id="employeeResults"></span> <span id="loading" style="display:none;"> <img src="images/indicator.gif" alt="" /> Loading ... </span> </div> <script type="text/javascript"> <!-- var departments = null; Sys.Application.add_load(page_load); Sys.Application.add_unload(page_unload); function page_load(sender, e){ departments = $get("Departments"); $addHandler(departments, "change", departments_onchange); } function page_unload(sender, e){ $removeHandler(departments, "change", departments_onchange); } function departments_onchange(sender, e){ $get("employeeResults").innerHTML = ""; $get("loading").style.display = "block"; var selectedValue = departments.value; HRService.GetEmployeeCount(selectedValue, onSuccess); } function onSuccess(result){ $get("loading").style.display = "none"; $get("employeeResults").innerHTML = "Employee count: " + result; } //--> </script> </form> </body> </html>and the service:
<%@ WebService Language="C#" Class="HRService" %> using System; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Web.Script.Services; [ScriptService] [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class HRService : System.Web.Services.WebService { [ScriptMethod] [WebMethod] public int GetEmployeeCount(string department) { System.Threading.Thread.Sleep(2000); return HumanResources.GetEmployeeCount(department); } }or like this:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ServerCentric.aspx.cs" Inherits="ServerCentric" %> <!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 id="Head1" runat="server"> <title>Employee Lookup</title> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <h2>Employee Lookup</h2> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <div> <asp:ListBox AutoPostBack="true" runat="server" ID="Departments" OnSelectedIndexChanged="Departments_SelectedIndexChanged"> <asp:ListItem Text="Engineering" Value="Engineering" /> <asp:ListItem Text="Human Resources" Value="HR" /> <asp:ListItem Text="Sales" Value="Sales" /> <asp:ListItem Text="Marketing" Value="Marketing" /> </asp:ListBox> </div> <br /> <div> <asp:Label ID="EmployeeResults" runat="server" /> </div> </ContentTemplate> </asp:UpdatePanel> <asp:UpdateProgress ID="UpdateProgress1" runat="server"> <ProgressTemplate> <img src="images/indicator.gif" alt="Loading" /> Loading ... </ProgressTemplate> </asp:UpdateProgress> </form> </body> </html>moshik.salem
Member
34 Points
124 Posts
Re: server-centric vs. client-centric approaches question
Jul 27, 2012 11:28 AM|LINK
to do the implementation with a web service or with the ajax server controls?
chetan.sarod...
All-Star
65839 Points
11163 Posts
Re: server-centric vs. client-centric approaches question
Jul 30, 2012 03:47 AM|LINK
Refer this
http://blogs.msdn.com/b/publicsector/archive/2006/05/22/604367.aspx?Redirected=true
http://blog.epigent.com/2011/09/server-centric-and-client-centric-web.html
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.