title: Calling SignalR hub clients from elsewhere in system
body: <p>I've set up a SignalR hub to communicate between the server and client. The hub server side code is stored in a class called Hooking.cs. What I want is to be able to call a method defined in Hooking.cs to allow me to broadcast messages to any connected clients from anywhere in my application. It seems that a new instance of Hooking.cs is created for every client/server call, so I had hoped that I would be able to use something like</p>
  
  <pre><code>var hooking = new Hooking();
  hooking.Test();
  </code></pre>
  
  <p>with the method Test() defined in Hooking.cs such as</p>
  
  <pre><code>public static void Test() {
      Clients.test()
  }
  </code></pre>
  
  <p>and with a the client side javascript</p>
  
  <pre><code>var hooking = $.connection.hooking;
  hooking.test = function() { alert("test worked"); };
  $.connection.hub.start()
  </code></pre>
  
  <hr>
  
  <p>Unfortunately it isn't that simple, as Clients is not static, so not accessible from a static method.</p>
  
  <p>Looking through the SignalR source code I came across a method that looked promising, <code>Hubs.Invoke(string hubName, string method, params object[] args)</code>, so I would hope I could use something such as <code>Hubs.Invoke("Hooking", "Test")</code> but I can't make it work.</p>
  
  <p>Any help with this would be hugely appreciated</p>