Category WCF

Get Records By WCF using JQuery in and Display in Table

Category: ASP.NETJQUERYWCF Comments: No comments


First Register your ajax enabled WCF service

<asp:ScriptManager ID=”ScriptManager1″ runat=”server”>
<asp:ServiceReference Path=”~/Service.svc” />

<asp:ButtonĀ  ID=”btnCall” runat=”server” Text=”Get Record” />
<div id=”bindData”>

Add below Section to Head

<script src=”jquery-1.7.2.min.js” type=”text/javascript”></script>
<script type=”text/javascript”>

$(document).ready(function () {

//Button Click Function
$(“input[id$=btnCall]“).click(function () {

//Get Record by Ajax Enabled WCF Service
Service.GetAllRecord(onSuccess, OnFailed);
return false;


// Table Creating Funtion

function GetElementDetail(id, name, price) {
var detail = “<tr>”;
detail += “<td>”;
detail += “” + id + “</td>”;
detail += “<td>”;
detail += ” ” + name + “</td>”;
detail += “<td>”;
detail += “” + price + “</td>”;
detail += “<td>”;
detail += “” + “<a href=’javascript:Edit(” + id + “)’ title=’Edit Item’ >Edit</a><a href=’javascript:Delete(” + id + “)’ title=’Delete Item’ onclick=’javascript:if(!confirm(\”Are you sure you want to delete ?\”)) return false’ >Delete</a></td>”;
detail += “</tr>”;
return detail;

//Success Function
function onSuccess(result) {

var tableString = “”;
var tableHead = “<thead style=’background-color: orange;’><tr><th>ID </th><th>Name</th><th>Price</th><th>Actions</th></tr></thead>”;
$(result).each(function (i) {

var id = result[i].id;
var name = result[i].name;
var price = result[i].price;
var strInner = GetElementDetail(id, name, price);
tableString = tableString + strInner;

$(“#bindData”).append(tableHead + tableString);
return false;
//Failed Function
function OnFailed() {
alert(‘Failed to Load Data.’);

function Edit(obj) {
alert(“Perform Edit Operation by ID ” + obj + “”)
function Delete(obj) {
alert(“Perform Delete Operation by ID” + obj + “”);

Use Ajax Enabled WCF Service


public GetDetails[] GetAllRecord()
// Add your operation implementation here
DataTable dt = GetProductDataTable();
List<GetDetails> objGet = new List<GetDetails>();
for (int i = 0; i < dt.Rows.Count; i++)
objGet.Add(new GetDetails() {
return objGet.ToArray();
public DataTable GetProductDataTable()
// Here we create a DataTable with three columns.
DataTable dtproduct = new DataTable();
dtproduct.Columns.Add(“ID”, typeof(int));
dtproduct.Columns.Add(“NAME”, typeof(string));
dtproduct.Columns.Add(“PRICE”, typeof(int));

// Here we add five DataRows.
dtproduct.Rows.Add(1, “Product1″, 100);
dtproduct.Rows.Add(2, “Product2″, 110);
dtproduct.Rows.Add(3, “Product3″, 120);
dtproduct.Rows.Add(4, “Product4″, 130);
dtproduct.Rows.Add(5, “Product5″, 140);

return dtproduct;
public struct GetDetails
public int id { get; set; }
public string name { get; set; }
public int price { get; set; }

Download Code
Get Records by WCF

Read More

Introduction to WCF

Category: WCF Comments: No comments

WCF stands for Windows Communication Foundation. It is Microsoft’s latest technology that enables applications in a distributed environment to communicate with each other.WCF is Microsoft’s unified programming model for building service-oriented applications. It enables developers to build secure, reliable, transacted solutions that integrate across platforms and interoperate with existing.

WCF is an umbrella technology that covers ASMX web services, .NET remoting, WSE, Enterprise Service, and System.Messaging. It is designed to offer a manageable approach to distributed computing, broad interoperability, and direct support for service orientation. WCF supports many styles of distributed application development by providing a layered architecture.

ABC of Windows Communication Foundation

What are the ABCs of WCF? “ABC” stands for address, binding and contract.

  1. Address (Where)

    It specifies the location of the service means, where the service is hosted. The service hosting URL may be like http://server/wcfService. Clients will use this location to communicate with your service.

  2. Binding (How)

    It specifies how the client will communicate to the service. We have different protocols (like http,tcp,named pipe,msmq) for the WCF to communicate to the client.

  3. Contract (What)

    It specifies what the service will do. For this purpose we have different contract like as Data Contract, Operation Contract, Message Contract, Fault Contract. I will discuss all these later.

WCF Hosting

A WCF service is a component that can be called by other applications. It must be hosted in an environment in order to be discovered and used by others. The WCF host is an application that controls the lifetime of the service. With .NET 3.0 and beyond, there are several ways to host the service.

  1. Self hosting

    A WCF service can be self-hosted, which means that the service runs as a standalone application and controls its own lifetime. This is the most flexible and easiest way of hosting a WCF service, but its availability and features are limited.

  2. Windows services hosting

    A WCF service can also be hosted as a Windows service. A Windows service is a process managed by the operating system and it is automatically started when Windows is started (if it is configured to do so). However, it lacks some critical features (such as versioning) for WCF services.

  3. IIS hosting

    A better way of hosting a WCF service is to use IIS. This is the traditional way of hosting a web service. IIS, by nature, has many useful features, such as process recycling, idle shutdown, process health monitoring, message-based activation, high availability, easy manageability, versioning, and deployment scenarios. All of these features are required for enterprise-level WCF services.

  4. Windows Activation Services hosting

    The IIS hosting method, however, comes with several limitations in the service-orientation world; the dependency on HTTP is the main culprit. With IIS hosting, many of WCF’s flexible options can’t be utilized. This is the reason why Microsoft specifically developed a new method, called Windows Activation Services, to host WCF services.

    Windows Process Activation Service (WAS) is the new process activation mechanism for Windows Server 2008 that is also available on Windows Vista. WAS hosting is possible only with IIS 7.0.Additional WCF components also plug into WAS to provide message-based activation over the other protocols that WCF supports, such as TCP, MSMQ, and named pipes. This allows applications that use the non-HTTP communication protocols to use the IIS features such as process recycling, rapid fail protection, and the common configuration systems that were only available to HTTP-based applications.

Read More