TechBubbles Microsoft Technology BLOG

What is new in ASP.NET Signal R2

This post outlines the some of the improvements in new version of SignalR that included in Visual Studio 2013. In this version 2 issues related performance, stability and API usage are addressed. What is SignalR? SignalR enables you to do the real time browser-server communication that uses the best technology client and server support.

image

SignalR API improvements

One of the first features that you can find is ability to send the same message or invoke the same method on multiple clients at same time using Groups or Client Ids.

image

The above method can be called from client side code which is taking a string array that represents the names of the groups. Now you have the Groups method on Clients and pass in groups list. In earlier version of SignalR the same can be achieved by looping over string array and invoke the same method essentially multiple times one time for each group.

image

Now you also have the ability to send the message directly to the user. In SignalR 1 this was handled on OnConnected method by getting the connection id and username from userinstance from somewhere in your application. This approach is still can be used.

Other areas where you can find the improvements are error handling, In SignalR by default if you throw an error inside the Hub invocation those errors don’t way back to the client. You will get a generic error message to the client. Now you have a new exception type HubException. You can throw this exception providing a user message and any other arbitrary data that is useful for client.

image

The client side invocation looks as follows

image

Now if you debug this code then you  can easily understand where the error is coming from, notice the source HubException.

image

Now it is easy to unit test the Hub methods on server side code. A new Startup class is introduced in SignalR2

image

The advantage of above Startup class is it is not directly tied up with ASP.NET so if you want to host the SignalR connection and Hubs in different process on custom server commonly known as self-hosting then you can do that now, all you need to do is bring the supported self-hosting Nuget packages and install in your application as shown below

image

About the author

Kalyan Bandarupalli

My name is kalyan, I am a software architect and builds the applications using Microsoft .NET technologies. Here I am trying to share what I feel and what I think with whoever comes along wandering to Internet home of mine.I hope that this page and its contents will speak for me and that is the reason I am not going to say anything specially about my self here.

Add Comment

TechBubbles Microsoft Technology BLOG

Follow me

Archives

Tag Cloud