Deep diving SignalR with ASP.NET MVC 6.
Speaker: Mr Sherman Chen - Telerik Senior Architect/Advocate with more than 15 years developing desktop, web and mobile apps
2. TOPICS
• Introduction to ASP.NET MVC 6 + ASP.NET 5
• Key Concepts of SignalR
• Quick Look at SignalR
• SignalR with ASP.NET MVC 6 deep-dive demo
• Questions & Answer
3. ASP.NET MVC 6 + ASP.NET 5
• ASP.NET is now on Mac and Linux
• No More Web Forms
• No More Visual Basic
• Tag Helpers versus MVC Helpers
• View Components
• Microsoft.AspNet.Mvc.Controller
• AngularJS
6. KEY CONCEPTS: “SERVER PUSHING”
“SignalR supports "server push"
functionality, in which server code can
call out to client code in the browser
using Remote Procedure Calls (RPC),
rather than the request-response model
common on the web today. ”
7. KEY CONCEPTS: TRANSPORTS
• HTML5 Transports
• WebSocket – only transport that establishes true two way persistent connection
• Server Sent Events - EventSource
• Comet Transports (makes use of HTTP)
• Forever Frame (only IE)
• Ajax Long Polling
9. KEY CONCEPTS: SPECIFYING A TRANSPORT
If you know the client’s capability…
connection.start({ transport: 'longPolling' });
If not, always make sure there is a fallback…
connection.start({ transport: ['webSockets','longPolling'] });
11. KEY CONCEPTS: CONNECTIONS & HUBS
• Persistent Connection
• Low-level communication protocol
• PersistentConnection class
• Hub
• High-level pipeline
• Allowing clients to call methods on servers
• Similarity to .NET Remoting
12. KEY CONCEPTS: HOW HUBS WORK
• Server-side calls a method on the client
• A packet is sent across (name of method + parameters)
• If the parameter is an object, it will be serialized as JSON
• Client checks to see if the method exists in client-side coding
• If exists, the method is executed using the deserialized parameter data.
13. KEY CONCEPTS: WHEN TO USE PERSISTENT
CONNECTION?
• The format of the actual message sent needs to be specified.
• The developer prefers to work with a messaging and dispatching model rather
than a remote invocation model.
• An existing application that uses a messaging model is being ported to use
SignalR.
17. ABIT ABOUT TELERIK
• UI Toolkits – Web Forms, MVC, Silverlight, Kendo UI, WinForms, WPF, UWP
(Windows 10), and many more.
• Telerik Test Studio – Automated Testing solution (Native Mobile Apps)
• Telerik Platform – Cross-platform Mobile App Development & Management
• Telerik Sitefinity – Web Content Management System
Remote Procedural Calls – from your server code, you can call the client code in your web browser
WebSocket
If you were to code an application directly using WebSockets, you can, but you will then need to write a lot of other code to manage the falling back of the WebSocket.
What this means is SignalR will continue to be updated to support changes in the underlying transport, providing your application a consistent interface across versions of WebSocket
Transports
SignalR is an abstraction over some of the transports required to pass information back and forth the server and client.
Starts with HTTP, and will be upgraded to WebSocket whenever available
WebSocket is most efficient when it comes down to the use of server memory
Server Sent Events:
If the browser supports Server Sent Events, which is basically all browsers except Internet Explorer.
Forever Frame:
Forever Frame creates a hidden IFrame which makes a request to an endpoint on the server that does not complete. The server then continually sends script to the client which is immediately executed, providing a one-way realtime connection from server to client.
The connection from client to server uses a separate connection from the server to client connection, and like a standard HTML request, a new connection is created for each piece of data that needs to be sent.
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.