Skip to content

johan-v-r/SignalR

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SignalR

The purpose of this repository is to show the different SignalR implementations available for an OWIN WebApi.

OWIN WebApi

NuGet Packages used:

  • Microsoft.Owin.SelfHost
  • Microsoft.AspNet.SignalR.SelfHost
  • And all related dependencies

Follow tutorial here

In the Startup class, where the OWIN configuration is set, we must include the SignalR configuration to run in the same pipeline.

I have created 2 hubs purely to show the difference of how they will be used in the front-end.

There is nothing special in the setup between them, except for the IHubContext in the Generated Proxy Hub which is only used when calling from a controller. So the IHubContext can be removed safely without breaking the normal functionality.

Front-End

The 2 front-end implementations are: (best explained here)

  • Generated Proxy
  • Manual Proxy (without generated proxy)

The major difference being:

  • if you want to get a .js script generated by SignalR on page load via <script> tags (see index.html) (Generated Proxy)
  • or only accessing the hubs when needed (Manual Proxy)

Other small differences include dynamic function calls vs event binding and invoking methods.

SignalR access from ApiController

As the request to the ApiController has a HTTP Context, we need to get the context for the Hub's WebSocket protocol.

For ease of use I have created a static IHubContext which can be used when calling the Hub's methods from the controllers, as seen here

Resources

http://www.asp.net/signalr/overview/deployment/tutorial-signalr-self-host

http://www.asp.net/signalr/overview/guide-to-the-api/hubs-api-guide-javascript-client

http://stackoverflow.com/questions/31169509/signalr-how-to-truly-call-a-hubs-method-from-the-server-c-sharp

About

SignalR Implementation Demo

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published