Copyright © 2018 ONE BCG. All rights reserved.
SignalR With ASP.NET MVC
2
Copyright © 2018 ONE BCG. All rights reserved.
Introduction
• What is SignalR?
• Why do we need it?
• Where can we use it?
• How does it work?
• SignalR backplanes
3
Copyright © 2018 ONE BCG. All rights reserved.
What is SignalR?
WHAT
4
Copyright © 2018 ONE BCG. All rights reserved.
SignalR?
• Real-time, open-source library, persistent connection
abstraction over HTTP for .NET
• Simple and powerful API’s
• Many techniques use to keep the logical connection up,
including retry logic if transport fail.
• Scaleout back plans.
5
Copyright © 2018 ONE BCG. All rights reserved.
Why do we need signalR?
WHY
6
Copyright © 2018 ONE BCG. All rights reserved.
Why do we need signalR?
• SignalR provides a simple API for creating server-to-client
remote procedure call(RPC) that call javascript functions in
client browsers from server-side .NET code.
• SignalR also includes API for connection management(for
instance, connect and disconnect events). It handle connection
management automatically.
7
Copyright © 2018 ONE BCG. All rights reserved.
Why do we need signalR?
• It can reach out to thousands of clients using service bus, SQL
server or Redis cache.
• Abstract away the network layer for bidirectional real-time
communications, thus helping developers focus on building the
application.
8
Copyright © 2018 ONE BCG. All rights reserved.
Where can we use it?
WHERE
9
Copyright © 2018 ONE BCG. All rights reserved.
Where can we use it?
• Dashboards
• Monitoring
• Job progress
• Real-time form
• Web games/ Chat rooms
• Trading
10
Copyright © 2018 ONE BCG. All rights reserved.
How does it work?
HOW
11
Copyright © 2018 ONE BCG. All rights reserved.
How does it work?
12
Copyright © 2018 ONE BCG. All rights reserved.
How does it work?
Order of network transports:-
HTML 5 Transports:-
• WebSockets
• Server Sent Events
Comet Transports (long-held HTTP request):-
• Forever Frame
• Ajax Long Polling
13
Copyright © 2018 ONE BCG. All rights reserved.
How does it work?
WebSockets
• A new HTML5 API enables bi-directional, full-duplex
communication between the browser and the server.
• It is the new standard defined as a part of HTML 5 to solve
two major problems of the current web:
- Overhead of HTTP (Network Throughput)
- Low Latency
14
Copyright © 2018 ONE BCG. All rights reserved.
How does it work?
Server sent event
• A technology, where a browser receives automatic updates
from a server via an HTTP connection, the Server-Sent Events
EventSource API is standardized as part of HTML5.
• The situation was also possible before, but the web page
would seek updates. With server-sent events, the updates
come automatically.
• It supports all major browsers, except Internet Explorer.
15
Copyright © 2018 ONE BCG. All rights reserved.
How does it work?
Forever Frame
● Forever Frame creates a hidden IFrame which requests to an
endpoint on the server that does not complete. The server then
continually sends a script to the client which is immediately
executed, providing a one-way realtime connection from server to
client.
16
Copyright © 2018 ONE BCG. All rights reserved.
Forever Frame continued..
● The connection from the client to server uses a separate
attachment from the server to client connection, and like a
standard HTML request, creates a new link for each piece of
data sent.
17
Copyright © 2018 ONE BCG. All rights reserved.
How does it work?
Ajax Long Polling
• Long polling does not create a persistent connection, but instead
polls the server with a request that stays open until the server
responds, at which point the connection closes, and a new
connection is requested immediately.
• This may introduce some latency while the connection resets.
18
Copyright © 2018 ONE BCG. All rights reserved.
How does it work?
• Fallback.
19
Copyright © 2018 ONE BCG. All rights reserved.
How does it work?
SignalR API & Architecture
The SignalR API contains two models for communicating between
clients and servers: Persistent Connections & Hubs Connection
Persistent Connections
• Low level access to communication.
• Direct developer access to network pipeline.
• Access to lot more communication events.
• Will be familiar to developers who have used connection-based
APIs such as WCF.
20
Copyright © 2018 ONE BCG. All rights reserved.
How does it work?
Hubs
• High level abstraction
• Built on top of Persistent Connections
• Least developer work.
• Works for majority of user.
• Will be familiar to developers who have used remote invocation
APIs such as .Net Remoting.
21
Copyright © 2018 ONE BCG. All rights reserved.
How does it work?
22
Copyright © 2018 ONE BCG. All rights reserved.
How does it work?
23
Copyright © 2018 ONE BCG. All rights reserved.
How does it work?
Demo Link
https://sahilsaini.azurewebsites.net/
24
Copyright © 2018 ONE BCG. All rights reserved.
How does it work?
Selecting which clients will receive the RPC
• Clients.All.refresh(message); // All connected clients
• Clients.Caller.refresh(message); // Only the calling client
• Clients.others.refresh(message); // All clients except the calling
client
• Clients.Client(Context.ConnectionId).refresh(message); // A specific
client identified by connection ID
25
Copyright © 2018 ONE BCG. All rights reserved.
How does it work?
Selecting which clients will receive the RPC
• clients.AllExcept(connectionId1,
connectionId2).refresh(message); // All connected clients except
the specified clients, identified by connection ID.
• clients.Group(groupName).refresh(message); // All connected
clients in a specified group.
• clients.Group(groupName).refresh(message); // All connected
clients in a specified group.
26
Copyright © 2018 ONE BCG. All rights reserved.
SignalR Backplanes
Backplane is basically for forward messages between servers in
scaleout environments.
Why we need it?
When you application scale out, clients can get routed to different
servers. A client that is connected to one server will not receive
messages sent from another server.
27
Copyright © 2018 ONE BCG. All rights reserved.
SignalR Backplanes
28
Copyright © 2018 ONE BCG. All rights reserved.
SignalR Backplanes
SignalR currently provides three backplanes:
• Azure Service Bus
• Redis
• SQL Server
29
Copyright © 2018 ONE BCG. All rights reserved.
SignalR Backplanes
SignalR scaleout with SQL Server:
30
Copyright © 2018 ONE BCG. All rights reserved.
SignalR Backplanes
SignalR scaleout with SQL Server:
• Install Microsoft.AspNet.SignalR.SqlServer package to signalR
application.
• Write below code in startup file:-
public void Configuration(IAppBuilder app)
{
// Any connection or hub wire up and configuration should go here
string sqlConnectionString = "Connecton string to your SQL DB";
GlobalHost.DependencyResolver.UseSqlServer(sqlConnectionString);
app.MapSignalR();
}
31
Copyright © 2018 ONE BCG. All rights reserved.
SignalR Backplanes
SignalR scaleout with Redis:
• Install Microsoft.AspNet.SignalR.StackExchangeRedis package to
web application
• Write below code in Startup file:-
32
Copyright © 2018 ONE BCG. All rights reserved.
SignalR Backplanes
SignalR scaleout with Azure service bus:
• Install Microsoft.AspNet.SignalR.ServiceBus package to web
application
• Write below code in Startup file:-
33
Copyright © 2018 ONE BCG. All rights reserved.
Azure SignalR
WHAT is Azure SignalR
• Azure SignalR Service simplifies the process of adding real-time web
functionality to applications over HTTP.
• This real-time functionality allows the service to push content
updates to connected clients, such as a single page web or mobile
application.
• Fully managed service.
34
Copyright © 2018 ONE BCG. All rights reserved.
Azure SignalR
Benefits using Azure SignalR Service
• Standard based
• Native ASP.NET Core support
• Broad client support
• Handle large-scale client connections
• Remove the burden to self-host SignalR
35
Copyright © 2018 ONE BCG. All rights reserved.
Azure SignalR
How to use Azure signalR
• Install Microsoft.Azure.SignalR.AspNet to web application
• Write below code in Startup file:-
36
Copyright © 2018 ONE BCG. All rights reserved.
Azure SignalR
How to use Azure signalR
37
Copyright © 2018 ONE BCG. All rights reserved.
Azure SignalR
Demo Link
https://testazuresignalr.azurewebsites.net/
38
Copyright © 2018 ONE BCG. All rights reserved.
Thank You
THANK YOU

Brushing skills on SignalR for ASP.NET developers

  • 1.
    Copyright © 2018ONE BCG. All rights reserved. SignalR With ASP.NET MVC
  • 2.
    2 Copyright © 2018ONE BCG. All rights reserved. Introduction • What is SignalR? • Why do we need it? • Where can we use it? • How does it work? • SignalR backplanes
  • 3.
    3 Copyright © 2018ONE BCG. All rights reserved. What is SignalR? WHAT
  • 4.
    4 Copyright © 2018ONE BCG. All rights reserved. SignalR? • Real-time, open-source library, persistent connection abstraction over HTTP for .NET • Simple and powerful API’s • Many techniques use to keep the logical connection up, including retry logic if transport fail. • Scaleout back plans.
  • 5.
    5 Copyright © 2018ONE BCG. All rights reserved. Why do we need signalR? WHY
  • 6.
    6 Copyright © 2018ONE BCG. All rights reserved. Why do we need signalR? • SignalR provides a simple API for creating server-to-client remote procedure call(RPC) that call javascript functions in client browsers from server-side .NET code. • SignalR also includes API for connection management(for instance, connect and disconnect events). It handle connection management automatically.
  • 7.
    7 Copyright © 2018ONE BCG. All rights reserved. Why do we need signalR? • It can reach out to thousands of clients using service bus, SQL server or Redis cache. • Abstract away the network layer for bidirectional real-time communications, thus helping developers focus on building the application.
  • 8.
    8 Copyright © 2018ONE BCG. All rights reserved. Where can we use it? WHERE
  • 9.
    9 Copyright © 2018ONE BCG. All rights reserved. Where can we use it? • Dashboards • Monitoring • Job progress • Real-time form • Web games/ Chat rooms • Trading
  • 10.
    10 Copyright © 2018ONE BCG. All rights reserved. How does it work? HOW
  • 11.
    11 Copyright © 2018ONE BCG. All rights reserved. How does it work?
  • 12.
    12 Copyright © 2018ONE BCG. All rights reserved. How does it work? Order of network transports:- HTML 5 Transports:- • WebSockets • Server Sent Events Comet Transports (long-held HTTP request):- • Forever Frame • Ajax Long Polling
  • 13.
    13 Copyright © 2018ONE BCG. All rights reserved. How does it work? WebSockets • A new HTML5 API enables bi-directional, full-duplex communication between the browser and the server. • It is the new standard defined as a part of HTML 5 to solve two major problems of the current web: - Overhead of HTTP (Network Throughput) - Low Latency
  • 14.
    14 Copyright © 2018ONE BCG. All rights reserved. How does it work? Server sent event • A technology, where a browser receives automatic updates from a server via an HTTP connection, the Server-Sent Events EventSource API is standardized as part of HTML5. • The situation was also possible before, but the web page would seek updates. With server-sent events, the updates come automatically. • It supports all major browsers, except Internet Explorer.
  • 15.
    15 Copyright © 2018ONE BCG. All rights reserved. How does it work? Forever Frame ● Forever Frame creates a hidden IFrame which requests to an endpoint on the server that does not complete. The server then continually sends a script to the client which is immediately executed, providing a one-way realtime connection from server to client.
  • 16.
    16 Copyright © 2018ONE BCG. All rights reserved. Forever Frame continued.. ● The connection from the client to server uses a separate attachment from the server to client connection, and like a standard HTML request, creates a new link for each piece of data sent.
  • 17.
    17 Copyright © 2018ONE BCG. All rights reserved. How does it work? Ajax Long Polling • Long polling does not create a persistent connection, but instead polls the server with a request that stays open until the server responds, at which point the connection closes, and a new connection is requested immediately. • This may introduce some latency while the connection resets.
  • 18.
    18 Copyright © 2018ONE BCG. All rights reserved. How does it work? • Fallback.
  • 19.
    19 Copyright © 2018ONE BCG. All rights reserved. How does it work? SignalR API & Architecture The SignalR API contains two models for communicating between clients and servers: Persistent Connections & Hubs Connection Persistent Connections • Low level access to communication. • Direct developer access to network pipeline. • Access to lot more communication events. • Will be familiar to developers who have used connection-based APIs such as WCF.
  • 20.
    20 Copyright © 2018ONE BCG. All rights reserved. How does it work? Hubs • High level abstraction • Built on top of Persistent Connections • Least developer work. • Works for majority of user. • Will be familiar to developers who have used remote invocation APIs such as .Net Remoting.
  • 21.
    21 Copyright © 2018ONE BCG. All rights reserved. How does it work?
  • 22.
    22 Copyright © 2018ONE BCG. All rights reserved. How does it work?
  • 23.
    23 Copyright © 2018ONE BCG. All rights reserved. How does it work? Demo Link https://sahilsaini.azurewebsites.net/
  • 24.
    24 Copyright © 2018ONE BCG. All rights reserved. How does it work? Selecting which clients will receive the RPC • Clients.All.refresh(message); // All connected clients • Clients.Caller.refresh(message); // Only the calling client • Clients.others.refresh(message); // All clients except the calling client • Clients.Client(Context.ConnectionId).refresh(message); // A specific client identified by connection ID
  • 25.
    25 Copyright © 2018ONE BCG. All rights reserved. How does it work? Selecting which clients will receive the RPC • clients.AllExcept(connectionId1, connectionId2).refresh(message); // All connected clients except the specified clients, identified by connection ID. • clients.Group(groupName).refresh(message); // All connected clients in a specified group. • clients.Group(groupName).refresh(message); // All connected clients in a specified group.
  • 26.
    26 Copyright © 2018ONE BCG. All rights reserved. SignalR Backplanes Backplane is basically for forward messages between servers in scaleout environments. Why we need it? When you application scale out, clients can get routed to different servers. A client that is connected to one server will not receive messages sent from another server.
  • 27.
    27 Copyright © 2018ONE BCG. All rights reserved. SignalR Backplanes
  • 28.
    28 Copyright © 2018ONE BCG. All rights reserved. SignalR Backplanes SignalR currently provides three backplanes: • Azure Service Bus • Redis • SQL Server
  • 29.
    29 Copyright © 2018ONE BCG. All rights reserved. SignalR Backplanes SignalR scaleout with SQL Server:
  • 30.
    30 Copyright © 2018ONE BCG. All rights reserved. SignalR Backplanes SignalR scaleout with SQL Server: • Install Microsoft.AspNet.SignalR.SqlServer package to signalR application. • Write below code in startup file:- public void Configuration(IAppBuilder app) { // Any connection or hub wire up and configuration should go here string sqlConnectionString = "Connecton string to your SQL DB"; GlobalHost.DependencyResolver.UseSqlServer(sqlConnectionString); app.MapSignalR(); }
  • 31.
    31 Copyright © 2018ONE BCG. All rights reserved. SignalR Backplanes SignalR scaleout with Redis: • Install Microsoft.AspNet.SignalR.StackExchangeRedis package to web application • Write below code in Startup file:-
  • 32.
    32 Copyright © 2018ONE BCG. All rights reserved. SignalR Backplanes SignalR scaleout with Azure service bus: • Install Microsoft.AspNet.SignalR.ServiceBus package to web application • Write below code in Startup file:-
  • 33.
    33 Copyright © 2018ONE BCG. All rights reserved. Azure SignalR WHAT is Azure SignalR • Azure SignalR Service simplifies the process of adding real-time web functionality to applications over HTTP. • This real-time functionality allows the service to push content updates to connected clients, such as a single page web or mobile application. • Fully managed service.
  • 34.
    34 Copyright © 2018ONE BCG. All rights reserved. Azure SignalR Benefits using Azure SignalR Service • Standard based • Native ASP.NET Core support • Broad client support • Handle large-scale client connections • Remove the burden to self-host SignalR
  • 35.
    35 Copyright © 2018ONE BCG. All rights reserved. Azure SignalR How to use Azure signalR • Install Microsoft.Azure.SignalR.AspNet to web application • Write below code in Startup file:-
  • 36.
    36 Copyright © 2018ONE BCG. All rights reserved. Azure SignalR How to use Azure signalR
  • 37.
    37 Copyright © 2018ONE BCG. All rights reserved. Azure SignalR Demo Link https://testazuresignalr.azurewebsites.net/
  • 38.
    38 Copyright © 2018ONE BCG. All rights reserved. Thank You THANK YOU