O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

Introduction to SignalR

1.350 visualizações

Publicada em

An introduction to SignalR

This deck was part of my presentation to Virtusa employees on an ASP.NET asynchronous, persistent signaling library known as SignalR
There is also a slide on how to use SignalR with SharePoint.

Date: August 2013

Follow / Tweet me: @ShehanPeruma

Publicada em: Software
  • Entre para ver os comentários

Introduction to SignalR

  1. 1. The entire contents of this document are subject to copyright with all rights reserved. All copyrightable text and graphics, the selection, arrangement and presentation of all information and the overall design of the document are the sole and exclusive property of Virtusa. Copyright © 2012 Virtusa Corporation. All rights reserved 2000 West Park Drive Westborough MA 01581 USA Phone: 508 389 7300 Fax: 508 366 9901 Introduction to SignalR SharePoint CEG | K-Talk Shehan Peruma August 23, 2013
  2. 2. 2 Agenda • Real-Time Web Technologies • SignalR • Getting Started • Hubs API • SignalR & SharePoint • Summary
  3. 3. 3 Real-Time Web Technologies
  4. 4. 4 What? • Stock Ticker • Live Scores • News Feeds • Dashboards • VoIP • Chat • Auctions • Activity Streams Improved User Experience & Server Performance D e f i n i t i o n : an application that functions within a time frame that the user senses as immediate or current. Real Time Web Technologies
  5. 5. 5 How? Multiple approaches exist to provide near real time functionality, but each has it’s own set of pros & cons. • Polling • Long Polling • Forever Frame (IE only) • Server Sent Events (SSE) • Web Sockets Real Time Web Technologies Server Client Server Client
  6. 6. 6 Response4 Response3 Response2 Response1 Web Sockets – Quick Intro. • Part of the Html 5 specification • Full-duplex (unlike HTTP) • Built on top of HTTP – can share HTTP ports (i.e. 80 & 443) • URL: ws:// & wss:// similar to http:// & https:// • Client & Server support required Real Time Web Technologies Server Client Request1 Request2 Request3 Request4 Time Frame3 Frame2 Frame1 Handshake Response Server Client Handshake Request Time Frame4 PollingWebSockets
  7. 7. 7
  8. 8. 8 • Initially developed by members of the ASP.NET team • Part of the ASP.NET Technologies • Open source and hosted on GitHub • Distributed via NuGet • Requires .NET 4.0 and above What is SignalR? S i g n a l R : An ASP.NET asynchronous, persistent signaling library that enables the real-time, multi-user web functionality for applications. SignalR
  9. 9. 9 Demo – A Simple Example
  10. 10. 11 Transports Long Polling Forever Frame Server Sent Events Web Sockets SignalR
  11. 11. 12 Demo – Transport Fallback
  12. 12. 14 Supported Clients & Hosts Client JavaScript Silverlight 5 Windows Phone 8 .NETWinRT iOS Android SignalR Host ASP.NET Self-Hosting (OWIN)
  13. 13. 15 Demo – Clients
  14. 14. 17 Connections & Hubs SignalR Persisted Connections (low-level) • Can communicate with 1 to N clients • Is an IHttpHandler • Requires a route to be defined • Limited to sending messages • You define the “protocol” Hubs (high-level) • Can communicate with 1 to N clients • Abstraction over PersistentConnection • Route automatically mapped (/signalr/hubs) • Can send messages and call methods • SignalR defines the protocol
  15. 15. 18 Hubs • Hub methods can be called by the clients (e.g. javascript) • Client methods can be called by the Hub • Can send messages to all or individual clients • Ability to add clients to groups • Messages can be sent to groups • Handles connection lifetime events SignalR
  16. 16. 19 jQuery Proxy • Two approaches: • with generated proxy • Use signalr.exe tool to create the proxy file. • Without proxy but ‘late binding’ • Can be accessed by navigating to http://yoursite/signalr/hubs • The proxy simplifies the code needed to communicate with the server SignalR
  17. 17. 20 Getting Started
  18. 18. 21 Installing NuGet Packages Getting Started Search for SignalRInstall Microsoft ASP.NET SignalR The required scripts & assemblies will be added to the project.
  19. 19. 22 Route Mapping Getting Started Defined in Global.asax Defines the routes the client will use to connect to the hub Part of System.Web.Routing
  20. 20. 23 Hub Class Getting Started Inherits from Microsoft.AspNet.SignalR.Hub Sends the message to all the clients by calling the clients broadcastMessage method Connected clients can call the Hubs NewMessage method
  21. 21. 24 Client (JavaScript) • Add reference to JavaScript files • Get reference to Hub • Wireup events • Start hub connection • Call hub methods Getting Started
  22. 22. 25 Demo – Code/App
  23. 23. 26 Hubs API
  24. 24. 27 Groups Hubs API • Provides the ability to broadcast messages to a selected set of clients • Groups are not persisted on the server • No API to retrieve group count or members The developer would need to keep track of this (e.g. database). Adding a client to a group Sending messages to a group
  25. 25. 28 Demo – Groups
  26. 26. 29 • Override the event handlers • OnConnected • OnReconnected • OnDisconnected • JavaScript methods available to notify client about connectivity states • $.connection.hub.connectionSlow • $.connection.hub.reconnecting • $.connection.hub.reconnected • $.connection.hub.disconnected Lifetime/Lifecycle Events Hubs API
  27. 27. 30 • Send data to connected clients by calling methods from outside the Hub HubContext Hubs API SignalR Client SignalR Server Windows Service/Scheduler The Hub classMethod belongs to a class that is not a Hub Call the client method
  28. 28. 31 Demo – HubContext
  29. 29. 32 • Authorize - specify which users or roles have access to a hub or method • Scaleout • Windows Azure Service Bus • Redis • SQL Server Other Features Hubs API
  30. 30. 33 SignalR & SharePoint
  31. 31. 34 • Create a ASP.NET Web Application • Install SignalR using nuget • Create the Hub • Update Global.asax • Publish • Set web application pool to use .Net Framework 4.0 (you might need to run the aspnet_regiis after changing the framework) • Optional: • Set the port to 80 and provide a host header (make sure to update the host file with the same header name) • Navigate to the site and ensure you can access the JavaScript hub proxy (i.e. http://signalr.mydomain.com/signalr/hubs) Hub Setup SignalR & SharePoint
  32. 32. 35 • Within the page/CEWP/Webpart,etc.. Add reference to the scripts in the hubs site • Set jQuery to support cross domain communication • Set the hub url • Start the connection Client Setup (SharePoint 2010) SignalR & SharePoint
  33. 33. 36 Demo – SignalR & SharePoint
  34. 34. 37 Summary
  35. 35. 38 Summary • Provides the ability to add real time web functionality to applications • Push data to clients and/or groups • Hubs enables remote procedure calls (RPCs) to be made from a server to connected clients and from clients to the server • Not limited to web clients
  36. 36. 39 Resources • SignalR documentation - http://www.asp.net/signalr • Pluralsight training - http://pluralsight.com/training/Player?author=christian- weyer&name=signalr-introduction-m2- realtime&mode=live&clip=0&course=signalr-introduction
  37. 37. 40 Q&A Q&A
  38. 38. 41 Thanks! Thank you for attending!
  39. 39. www.virtusa.com © 2012 All rights reserved. Virtusa and all other related logos are either registered trademarks or trademarks of Virtusa Corporation in the United States, the European Union, and/or India. All other company and service names are the property of their respective holders and may be registered trademarks or trademarks in the United States and/or other countries.

×