Skip to main content

SignalR Tutorial: Introduction to SignalR in ASP.Net

What is SignalR?

SignalR is open source .Net library managed by David Fowler and Damien Edwards and well supported by Microsoft and now it is part of ASP.Net framework as well. You can see this project on GitHub.

Interaction using SignalR

Key points about SignalR:

·         SignalR is invented by David Fowler and Damien Edwards in August 2011.
·         SignalR is an asynchronous signaling framework to help build real-time, multi-user interactive web applications.
·         Real time means connection and conversation happens in real time, for e.g. chat server.
·         It is built on top of ASP.NET (server side) and a JavaScript library (on the client side) that enables clients (browser) and server (ASP.NET based) components to have a bidirectional conversation.
·         SignalR will use WebSockets when it's available, and gracefully fallback to other technologies when it isn't, while your application code remains the same.
·         WebSocket is a new HTML5 API that enables bi-directional communication between the browser and server and that is exactly what we want to achieve through SignalR.
·         It maintains a persistent connection between client and server and lets the client send multiple messages to the server and the server replies those messages asynchronously.
·         It uses an existing technique called long polling and keeps the connections open between a client and web server.
·         It provides support for connection management, e.g. connect/disconnect events, grouping connections, authorization etc.
·         It also provides a very simple and high-level API for calling JQuery/JavaScript functions in your clients' browsers from server-side ASP.NET code (i.e. server to client RPC).
·         It can be considered as a solution dealing with stateless nature of web by making the web appear to behave in a stateful way.

Why do we need SignalR?

This question run in our mind whenever we learn any new technology and SignalR is not an exception in this case J

·         It is an open-source .NET library for building web applications that require real-time data updates or live user interaction.
·         Most common examples where SignalR can be used are news tickers, sport site, chat clients, stock or weather updates.
·         Any web application or web page that implements Ajax long polling to retrieve new data, is good candidate for using SignalR.
·         SignalR also enable us to create rich collaborative web applications in ASP.NET, for e.g. real-time gaming.

Prerequisites to create SignalR application: 

To get started with SignalR you will need a few things installed:

·         Visual Studio 2012 Express (or any version of Visual Studio 2012 Professional and up) or Visual Studio 2010 SP1.
·         2012 Express Development Tool.
·         For Visual Studio 2010, install ASP.NET MVC 4.
·         If you don’t have any of required tools then you can check ASP.Net download page and install them.

In next post we’ll use SignalR to create a sample chat application.

Popular posts from this blog

C#: Merging Excel cells with NPOI HSSFWorkbook

In this post we’ll see how to merge the two or more cell with each other while creating the excel sheet using NPOI.
Mentioned below is code to merge multiple cells, in this example we are merging first cell to fifth cell of first row (you can adjust row or cell range by passing particular parameters in CellRangeAddress).
//Created new Workbook var hwb = new NPOI.HSSF.UserModel.HSSFWorkbook(); //Create worksheet with name. var sheet = hwb.CreateSheet("new sheet"); //Create row and cell. var row = sheet.CreateRow(0); var cell = row.CreateCell(0); ; //Set text inside cell cell.SetCellValue("This is Merged cell"); cell.CellStyle.WrapText = true; //define cell range address // parameters: -> first row to last and first cell to last cell var cra = new NPOI.SS.Util.CellRangeAddress(0, 0, 0, 4); //Add merged region to sheet. sheet.AddMergedRegion(cra);
Hope this solution helps you J

Calculate Sum and average of two or more Textbox values using JQuery

We can calculate sum and average of values entered in textboxes with the help of small piece of jQuery code.
First of all let’s create a HTML form where we’ll ask user to enter marks in each subject, under body section add following HTML:
<tableclass="demo-table"> <trclass="label"> <tdcolspan="2">Please enter marks(0-99):</td> </tr> <tr> <td>English</td> <td> <inputtype="text"class="txtMarks"name="txtMarks"

Difference between Web API, WCF and Web Service

So now we have got the basic idea about Web API, now let’s do some comparison of Web API with WCF and web services.
Web Service WCF Web API Web services created as file with .asmx extension. WCF create with .svc extension Web API are simple class file with .cs(for C#) extension. Web API is inherited from “ApiController” and class name must end with “Controller”. It is SOAP based service and return data in XML form. It is also based on SOAP and return data in XML form. Web API is HTTP based service and by default it return data in JSON or XML form. It supports only HTTP protocol. It supports various protocols like TCP, HTTP, HTTPS, Named Pipes, and MSMQ. It supports HTTP protocol. It can be hosted only on IIS. It can be hosted with in the application or on IIS or using window service. It can be hosted with in the application or on IIS. It is not open source but can be consumed by any client that understands xml. It is not open source but can be consumed by any client t…