SlideShare a Scribd company logo
ASP.NET Core SignalR &
Xamarin.Forms
Connect ASP.NET Core SignalR service via .NET Standard 2.0 C#
client library in Xamarin.Forms
ASP.NET Core SignalR
• A re-designed SignalR(http://signalr.net/) library for ASP.NET
Core 2.1 to provide real-time communication:
http://github.com/aspnet/signalr
• Not compatible with old ASP.NET SignalR.
• Existing Application that use ASP.NET SignalR or ASP.NET Core
SignalR:
• Office 365 real-time document co-authoring: http://bit.ly/2KIZjrb
• Visual Studio Live Share: http://bit.ly/2Nl8Aak
ASP.NET Core SignalR Features
• Multiple transport mechanism:
• Websocket: http://bit.ly/2MLVwtL
• Server-Send event: http://bit.ly/2KuvkXW
• Long Polling: http://bit.ly/2lOvg6t
• Hub concepts for client & server communication:
• Hub protocols: text based JSON & binary based MessagePack (
http://msgpack.org/ )
• Support 3 RPC style:
1. Server RPC call
2. Server Streaming RPC call
3. Server Call Client defined function
ASP.NET Core SignalR Features
• Hub Protocol spec is opened:
http://github.com/aspnet/SignalR/blob/master/specs/HubProtocol.m
d
• Provide many language implementation of client library:
• JavaScript: http://www.npmjs.com/package/@aspnet/signalr
• C#: http://www.nuget.org/packages/Microsoft.AspNetCore.SignalR.Client/
• C++ & Java Client are under development and will release stable version with
ASP.NET Core 2.2 timeline.
• 3rd Party:
• Swift : http://github.com/moozzyk/SignalR-Client-Swift
• RxJs enabled Js client: http:///www.npmjs.com/package/@ssv/signalr-client
ASP.NET Core SignalR Features
• Hub support ASP.NET Core Authentication mechanism
• Cookie
• JWT Auth Token
• Service instance can be scale-out using Redis on-premises,
using Azure SignalR Service(https://aka.ms/signalr_service ) in
cloud.
• Note: ASP.NET SignalR can scale-out via Azure Service Bus, but
there’s no plan for ASP.NET Core SignalR right now:
https://github.com/aspnet/SignalR/issues/1676
Xamarin & ASP.NET Core SignalR
• Using ASP.NET Core SignalR technology, we can build a cross
platform/device broadcasting system via Xamarin.
• Demo code:
http://bit.ly/2KHv57D
Xamarin.Forms as Core SignalR client
Using following Nuget Package in Xamarin.Forms project:
• Microsoft.AspNetCore.SignalR.Client:
https://www.nuget.org/packages/Microsoft.AspNetCore.SignalR.Client/
• Microsoft.Extensions.Logging.Console:
(for iOS & Android logging)
https://www.nuget.org/packages/Microsoft.Extensions.Logging.Console/
• Microsoft.Extensions.Logging.Debug:
(for UWP logging)
https://www.nuget.org/packages/Microsoft.Extensions.Logging.Debug/
• System.Threading.Channels:
(for invoke Server Streaming RPC call)
https://www.nuget.org/packages/System.Threading.Channels/
Xamarin.Forms as Core SignalR client
• Hub: a connection joint that client & sever can call their defined
methods mutually.
Server
Client #1
Client #2
Client #3
Hub
Xamarin.Forms as Core SignalR client
• On Client side, use “HubConnection(http://bit.ly/2tRduE6)” to
access the Server Method defined in Hub.
• To create HubConnection object, using
“HubConnectionBuilder(http://bit.ly/2MLLGYC)” to create.
• HubConnectionBuilder has many Fluent-API style extension
method to configure it. (ASP.NET Core configuration style)
Xamarin Form using ASP.NET Core SignalR client
Xamarin.Forms as Core SignalR client
• This kind of “Code as Configuration” coding style is very
modifiable based on demand, and can be refactored to a clear
style using Action Delegate:
http://www.tutorialsteacher.com/csharp/csharp-action-delegate
Xamarin.Forms as Core SignalR client
• Once HubConneciton instance is created, call StartAsync() to
connect to remote ASP.NET Core SignalR server, call
StopAsync() or DisposeAsync() to tear down connection,
HubConnection object cannot be re-used, must create it every
time when starting a new connection.
Xamarin.Forms as Core SignalR client
• Server RPC call : (http://bit.ly/2KKDXN8)
• Use HubConnectionExtensions.InvokeAsync<TResult>()
extension method(http://bit.ly/2MOpy03 ) to get RPC call result.
Xamarin.Forms as Core SignalR client
• Server Streaming RPC call: http://bit.ly/2tQLbp4
• Use
HubConnectionExtensions.StreamAsChannelAsync<TResult>()
extension method (http://bit.ly/2zfC1bc),
• Which needs additional New Type called
“ChannelReader(http://bit.ly/2MJARXi)” from .NET Core runtime, that
is not documented in official docs yet.
Channel(http://bit.ly/2KJAkXG) is a kind of Data Queue that
mimics Go’s “Buffered Channel(http://bit.ly/2IRo56K)” concept:
https://github.com/stephentoub/corefxlab/blob/master/src/Syst
em.Threading.Tasks.Channels/README.md
Xamarin.Forms as Core SignalR client
• Server Streaming RPC call can be cancelled from client via Set
Cancellation token parameter in
HubConnectionExtensions.StreamAsChannelAsync<TResult>()
Xamarin.Forms as Core SignalR client
• Server Call Client defined function: (http://bit.ly/2lT4cDf)
Register client function using HubConnection.On() or
HubConnectionExtensions.On(http://bit.ly/2IQ0Auw) API:
Other Notes
Xamarin Client need to use latest preview of Visual Studio 2017 15.8
preview 3 or Visual Studio for Mac 7.6 preview 3:
https://github.com/aspnet/Announcements/issues/305
• UWP on Windows 10 Mobile OS is not support since .NET Standard
2.0 support for Windows 10 UWP comes in 2017 Fall Creators
Update.
• UWP logging has to use AddDebug(), not AddConsole().
• JWT Authentication is configured on HubConnectionBuilder’s
WithUrl() extension method:
https://github.com/aspnet/SignalR/blob/948ebf34ece11918804f443b65c6a053dfc
8f35c/samples/JwtClientSample/Program.cs#L38
• Local debugging & testing can use ngrok(http://ngrok.com) for real
device connection.
Resources
• Code Magazine 2018 Jul/Aug issue:
http://www.codemag.com/Magazine/Issue/JulAug18
• Official doc: http://docs.microsoft.com/en-
us/aspnet/core/signalr/dotnet-client
• ASP.NET Core SignalR source code repo:
http://github.com/aspnet/signalr
• ASP.NET Core sample code repo:
http://github.com/aspnet/SignalR-samples
• Build 2018 Introduction Video:
https://channel9.msdn.com/Events/Build/2018/BRK2147

More Related Content

PPTX
Building a piano with the Web Audio API - Sophie
PPTX
Real-Time Communication
PPTX
ASP.NET MVC 5 and SignalR 2
PPTX
signalr
PPTX
Real time Communication with Signalr (Android Client)
PPTX
Web e device in real time con asp.net Signal R
PPTX
Building Real Time Applications with ASP.NET SignalR 2.0 by Rachel Appel
PPTX
SignalR: Above & Beyond Chat
Building a piano with the Web Audio API - Sophie
Real-Time Communication
ASP.NET MVC 5 and SignalR 2
signalr
Real time Communication with Signalr (Android Client)
Web e device in real time con asp.net Signal R
Building Real Time Applications with ASP.NET SignalR 2.0 by Rachel Appel
SignalR: Above & Beyond Chat

Similar to Xamarin Form using ASP.NET Core SignalR client (20)

PPTX
SignalR powered real-time x-plat mobile apps!
PPTX
SignalR Powered X-Platform Real-Time Apps!
PPTX
Real Time Apps with SignalR Core
PPTX
Signal r core workshop - netconf
PPTX
SignalR Overview
PPTX
Real-time Communication using SignalR and cloud
PPTX
Signal r
PPTX
SignalR
PPTX
Real Time App with SignalR
PDF
SignalR: Add real-time to your applications
PDF
PPTX
SignalR aplicaciones en tiempo real
PPTX
.NET Core Today and Tomorrow
PPTX
How To Build Real-Time Applications With ASP.NET Core SignalR
PPTX
SignalR Dublin ALT.NET
PPSX
Signalr with ASP.Net part2
PDF
Fancy Features in Asp.Net Core SignalR
PPT
Getting started with ASPNET Core SignalR
PPTX
SignalR with asp.net
PDF
SignalR or gRPC: Choosing the Right Technology for Real-Time Communication in...
SignalR powered real-time x-plat mobile apps!
SignalR Powered X-Platform Real-Time Apps!
Real Time Apps with SignalR Core
Signal r core workshop - netconf
SignalR Overview
Real-time Communication using SignalR and cloud
Signal r
SignalR
Real Time App with SignalR
SignalR: Add real-time to your applications
SignalR aplicaciones en tiempo real
.NET Core Today and Tomorrow
How To Build Real-Time Applications With ASP.NET Core SignalR
SignalR Dublin ALT.NET
Signalr with ASP.Net part2
Fancy Features in Asp.Net Core SignalR
Getting started with ASPNET Core SignalR
SignalR with asp.net
SignalR or gRPC: Choosing the Right Technology for Real-Time Communication in...
Ad

More from Chen Yu Pao (8)

PPTX
HoloLens 2的 MR(Mixed Reality)開發入門
PPTX
SkiaSharp on Xamarin Forms
PPTX
ReactiveUI Xamarin.Forms
PPTX
WebSocket on client & server using websocket-sharp & ASP.NET Core
PPTX
Xamarin ARKit Introduction 01
PPTX
Xamarin native forms
PPTX
Xamarin的Azure後端懶人包
PPTX
Proto actor 串接 Go 與 C# 簡易上手
HoloLens 2的 MR(Mixed Reality)開發入門
SkiaSharp on Xamarin Forms
ReactiveUI Xamarin.Forms
WebSocket on client & server using websocket-sharp & ASP.NET Core
Xamarin ARKit Introduction 01
Xamarin native forms
Xamarin的Azure後端懶人包
Proto actor 串接 Go 與 C# 簡易上手
Ad

Recently uploaded (20)

PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
System and Network Administraation Chapter 3
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
System and Network Administration Chapter 2
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PPTX
Online Work Permit System for Fast Permit Processing
PDF
Nekopoi APK 2025 free lastest update
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
CHAPTER 2 - PM Management and IT Context
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Which alternative to Crystal Reports is best for small or large businesses.pdf
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PTS Company Brochure 2025 (1).pdf.......
How to Migrate SBCGlobal Email to Yahoo Easily
System and Network Administraation Chapter 3
2025 Textile ERP Trends: SAP, Odoo & Oracle
VVF-Customer-Presentation2025-Ver1.9.pptx
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
System and Network Administration Chapter 2
ISO 45001 Occupational Health and Safety Management System
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Design an Analysis of Algorithms I-SECS-1021-03
ManageIQ - Sprint 268 Review - Slide Deck
Online Work Permit System for Fast Permit Processing
Nekopoi APK 2025 free lastest update
Operating system designcfffgfgggggggvggggggggg
Design an Analysis of Algorithms II-SECS-1021-03
CHAPTER 2 - PM Management and IT Context

Xamarin Form using ASP.NET Core SignalR client

  • 1. ASP.NET Core SignalR & Xamarin.Forms Connect ASP.NET Core SignalR service via .NET Standard 2.0 C# client library in Xamarin.Forms
  • 2. ASP.NET Core SignalR • A re-designed SignalR(http://signalr.net/) library for ASP.NET Core 2.1 to provide real-time communication: http://github.com/aspnet/signalr • Not compatible with old ASP.NET SignalR. • Existing Application that use ASP.NET SignalR or ASP.NET Core SignalR: • Office 365 real-time document co-authoring: http://bit.ly/2KIZjrb • Visual Studio Live Share: http://bit.ly/2Nl8Aak
  • 3. ASP.NET Core SignalR Features • Multiple transport mechanism: • Websocket: http://bit.ly/2MLVwtL • Server-Send event: http://bit.ly/2KuvkXW • Long Polling: http://bit.ly/2lOvg6t • Hub concepts for client & server communication: • Hub protocols: text based JSON & binary based MessagePack ( http://msgpack.org/ ) • Support 3 RPC style: 1. Server RPC call 2. Server Streaming RPC call 3. Server Call Client defined function
  • 4. ASP.NET Core SignalR Features • Hub Protocol spec is opened: http://github.com/aspnet/SignalR/blob/master/specs/HubProtocol.m d • Provide many language implementation of client library: • JavaScript: http://www.npmjs.com/package/@aspnet/signalr • C#: http://www.nuget.org/packages/Microsoft.AspNetCore.SignalR.Client/ • C++ & Java Client are under development and will release stable version with ASP.NET Core 2.2 timeline. • 3rd Party: • Swift : http://github.com/moozzyk/SignalR-Client-Swift • RxJs enabled Js client: http:///www.npmjs.com/package/@ssv/signalr-client
  • 5. ASP.NET Core SignalR Features • Hub support ASP.NET Core Authentication mechanism • Cookie • JWT Auth Token • Service instance can be scale-out using Redis on-premises, using Azure SignalR Service(https://aka.ms/signalr_service ) in cloud. • Note: ASP.NET SignalR can scale-out via Azure Service Bus, but there’s no plan for ASP.NET Core SignalR right now: https://github.com/aspnet/SignalR/issues/1676
  • 6. Xamarin & ASP.NET Core SignalR • Using ASP.NET Core SignalR technology, we can build a cross platform/device broadcasting system via Xamarin. • Demo code: http://bit.ly/2KHv57D
  • 7. Xamarin.Forms as Core SignalR client Using following Nuget Package in Xamarin.Forms project: • Microsoft.AspNetCore.SignalR.Client: https://www.nuget.org/packages/Microsoft.AspNetCore.SignalR.Client/ • Microsoft.Extensions.Logging.Console: (for iOS & Android logging) https://www.nuget.org/packages/Microsoft.Extensions.Logging.Console/ • Microsoft.Extensions.Logging.Debug: (for UWP logging) https://www.nuget.org/packages/Microsoft.Extensions.Logging.Debug/ • System.Threading.Channels: (for invoke Server Streaming RPC call) https://www.nuget.org/packages/System.Threading.Channels/
  • 8. Xamarin.Forms as Core SignalR client • Hub: a connection joint that client & sever can call their defined methods mutually. Server Client #1 Client #2 Client #3 Hub
  • 9. Xamarin.Forms as Core SignalR client • On Client side, use “HubConnection(http://bit.ly/2tRduE6)” to access the Server Method defined in Hub. • To create HubConnection object, using “HubConnectionBuilder(http://bit.ly/2MLLGYC)” to create. • HubConnectionBuilder has many Fluent-API style extension method to configure it. (ASP.NET Core configuration style)
  • 11. Xamarin.Forms as Core SignalR client • This kind of “Code as Configuration” coding style is very modifiable based on demand, and can be refactored to a clear style using Action Delegate: http://www.tutorialsteacher.com/csharp/csharp-action-delegate
  • 12. Xamarin.Forms as Core SignalR client • Once HubConneciton instance is created, call StartAsync() to connect to remote ASP.NET Core SignalR server, call StopAsync() or DisposeAsync() to tear down connection, HubConnection object cannot be re-used, must create it every time when starting a new connection.
  • 13. Xamarin.Forms as Core SignalR client • Server RPC call : (http://bit.ly/2KKDXN8) • Use HubConnectionExtensions.InvokeAsync<TResult>() extension method(http://bit.ly/2MOpy03 ) to get RPC call result.
  • 14. Xamarin.Forms as Core SignalR client • Server Streaming RPC call: http://bit.ly/2tQLbp4 • Use HubConnectionExtensions.StreamAsChannelAsync<TResult>() extension method (http://bit.ly/2zfC1bc), • Which needs additional New Type called “ChannelReader(http://bit.ly/2MJARXi)” from .NET Core runtime, that is not documented in official docs yet. Channel(http://bit.ly/2KJAkXG) is a kind of Data Queue that mimics Go’s “Buffered Channel(http://bit.ly/2IRo56K)” concept: https://github.com/stephentoub/corefxlab/blob/master/src/Syst em.Threading.Tasks.Channels/README.md
  • 15. Xamarin.Forms as Core SignalR client • Server Streaming RPC call can be cancelled from client via Set Cancellation token parameter in HubConnectionExtensions.StreamAsChannelAsync<TResult>()
  • 16. Xamarin.Forms as Core SignalR client • Server Call Client defined function: (http://bit.ly/2lT4cDf) Register client function using HubConnection.On() or HubConnectionExtensions.On(http://bit.ly/2IQ0Auw) API:
  • 17. Other Notes Xamarin Client need to use latest preview of Visual Studio 2017 15.8 preview 3 or Visual Studio for Mac 7.6 preview 3: https://github.com/aspnet/Announcements/issues/305 • UWP on Windows 10 Mobile OS is not support since .NET Standard 2.0 support for Windows 10 UWP comes in 2017 Fall Creators Update. • UWP logging has to use AddDebug(), not AddConsole(). • JWT Authentication is configured on HubConnectionBuilder’s WithUrl() extension method: https://github.com/aspnet/SignalR/blob/948ebf34ece11918804f443b65c6a053dfc 8f35c/samples/JwtClientSample/Program.cs#L38 • Local debugging & testing can use ngrok(http://ngrok.com) for real device connection.
  • 18. Resources • Code Magazine 2018 Jul/Aug issue: http://www.codemag.com/Magazine/Issue/JulAug18 • Official doc: http://docs.microsoft.com/en- us/aspnet/core/signalr/dotnet-client • ASP.NET Core SignalR source code repo: http://github.com/aspnet/signalr • ASP.NET Core sample code repo: http://github.com/aspnet/SignalR-samples • Build 2018 Introduction Video: https://channel9.msdn.com/Events/Build/2018/BRK2147