SignalR(Push Services) – Part 2

Explained about SignalR clients and consuming SignalR with various clients( Web, Windows and Windows Phone)
  • Hub Clients
    • Hub consumers can be classic client application or other service/hubs
    • SignalR provides variety of client libraries(.Net4.0+, WinRT, WindosPhone8, SilverLight 5, JQuery, c++)
    • JQuery Client:
      • SignalR JQuery plugin offers two approaches
        • Proxy based with generated proxy
          • Automated proxy code via signalr/hubs/
            • Scripts generated based on hubs declaration in .Net
            • 'Contract' if you will
          • Optionally: create static proxy file via signalr.exe tool
          • Hubs become properties on $.connection
            • E.g. $.connection.chatHub
            • Hub name camel cased
        • Without Proxy but 'Late binding'
          • We can also use late binding approach
          • Simple steps
            • Create Hub Connection
            • Get dynamic Proxy
              • Proxy = $.hubConnection().createHubProxy("Chat");
              • proxy.on(''newMessage', onNewMessage);
            • Wire up events based on method/event handler name via on
            • Start & invoke methods based on method name via invoke
      • .Net Client
        • NuGet package contains "Microsoft.AspNet.SignalR.Client"
        • Mental model resembles proxy-less Java script approach
        • Steps:
          • Create HUB Connection
          • Create Hub proxy via CreateHubProxy
          • Wire up event handlers via On
          • Start connection with Start()
          • Call methods via Invoke()
    • Client using JQuery [ Sample]
      • Get reference to hub
        • Add dynamic script reverence to "signalr/hubs/" and start the connection in Jquery ($.connection.chat.Start();)
        • To create hub proxy
          • Add package "Microsoft/AspNet/SignalR.Utils.1.0.0"
          • In command prompt, execute "Microsoft/AspNet/SignalR.Utils.1.0.0\tools\signalr.exe ghp /url://http://localhost:1246/" will create server.js
          • Two properties will be exposed in jquery
            • [hub].server.
            • [hub].client.

Comments

Popular posts from this blog

BDD - Acceptance Test Driven Development

Angular JS – Part 2

.Net Collections