One of the coolest features in the latest version of the .Net framework is the open source, real-time web functionality library of SignalR.
If you’re not familiar with it, please take the time to learn about it because it might be a “game changer” in developing ASP.NET web applications.
Basically, “ASP.NET SignalR is a new library for ASP.NET developers that makes developing real-time web functionality easy. SignalR allows bi-directional communication between server and client. Servers can now push content to connected clients instantly as it becomes available. SignalR supports Web Sockets, and falls back to other compatible techniques for older browsers. SignalR includes APIs for connection management (for instance, connect and disconnect events), grouping connections, and authorization.”
Here’s a brief look at its architecture:
If you are familiar with SignalR, you should probably consider some less-traditional / more creational ways to use it , rather than using it for the standard “chat-based” functionally.
Developing web store applications and web application I found SignalR useful more than once:
Server to client messages
Well, this is obvious, back office application would like to send some message to its’ customers or employees.
Client application user subscribes to a notification hub, while back office application sends a message to the subscribed users (described in the diagram above).
Another example might be an windows service agent, running on a services server, querying the database for new changes (for example order changes to a customer) and sends (via the web server to a notification hub) notification to the subscribed clients.
You might use a MVC / web API server that receives the requests and encapsulates the functionality and hides it for the service agent.
Data and View synchronization between clients
Let’s go back to the previous example that includes a windows store application handling orders for customers and a web based back office handing and monitoring the order’s life cycle (assigning the order to an employee, freezing it, canceling , monitoring and etc.)
We can use the “Real time” functionality (a term that is a stranger for web developers J ) of SignalR to really bring “Real time” to web applications.
By creating subscription groups per order, branch and so on , we can receive real time updates of these, the client applications (the back office being a client in this scenario) is subscribing to the same subscription group for the order as the windows store app,
This way, any change made by the employee or the back office manager will automatically be reflected upon all clients.
It’s really brings a “Real Time” web to life and being some a small and light-weight library, it’s very easy to implement on all HTML based clients.
SignalR as a Communication tool
After using this great library for a while, I’ve really started looking at it as a tool for communication, any kind of communication.
Windows store application (at least in their 8.0 version) have their limitations. While trying to open sockets to external devices (like a scanner for example), I’ve had to use a windows component (external to the windows store application) in order to communicate with its server APIs.
This involves a lot for work and several architecture components that were not necessary needed to begin with.
SignalR to the rescue! Using a self-hosted SignalR web application, managing sockets are obsolete! Just have the client and the device API (in this case, a scanner) subscribe to notification groups and you can transfer commands and data in a dual fashion.
Although, SignalR has been around for a while, I can’t help but thinking it was over looked by many people.
I encourage you to consider it in your application architecture.