title: calling SignalR hub from WebAPI controller issues
body: <p>I cannot figure out how I can call into a SignalR hub from a WebAPI ApiController.  I have put together a sample you can download <a href="https://skydrive.live.com/redir?resid=EDAFB4DBECFEE2EA!23072&amp;authkey=!AJSMQJ0RzAPlz3Y" rel="noreferrer">here</a> that simplifies the problem and demonstrates the issue.</p>
  
  <ol>
  <li>I created a new project from the ASP.NET MVC WebAPI template.  </li>
  <li>I added a new SignalR Hub to the project called ChatHub.</li>
  <li>Added a HTML page that on load, connects to ChatHub, joins to a group and sends a message to that group.  This works great.</li>
  <li>HTML page also has a button that when clicked will fire an ajax call to the ValuesController's post method.  In the ValuesController's post method, I want to broadcast a message to all the connected clients of the group.  I cannot get this to work.  </li>
  </ol>
  
  <p>I have a simple SignalR hub with just 2 methods.</p>
  
  <pre><code>[HubName("chat")]
  public class ChatHub : Hub
  {
      public void Join(string room)
      {
          // NOTE: this is not persisted - ....
          Groups.Add(Context.ConnectionId, room);
      }
  
      public void Send(string room, string message)
      {
          var msg = String.Format(
              "{0}: {1}", Context.ConnectionId, message);
          Clients.Group(room).newMessage(msg);
      }
  }
  </code></pre>
  
  <p>I created a very simple HTML page that connects to the Chat hub when the DOM is ready as shown here.</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Simple Chat&lt;/title&gt;
      &lt;script src="Scripts/jquery-1.8.2.js" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script src="Scripts/jquery.signalR-1.0.0.js"&gt;&lt;/script&gt;
      &lt;script src="signalr/hubs"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
          var chat;
  
          //$(function () {
          //    connectToHubs();
          //});
          $(connectToHubs);
          function connectToHubs() {
              $.connection.hub.logging = true;
  
              chat = $.connection.chat;
              chat.client.newMessage = onNewMessage;
  
              $.connection.hub.start({ transport: 'longPolling' }).done(function () {
                  chat.server.join("TestGroup").done(function () {
                      chat.server.send("TestGroup", "message from html");
                  });
              });
  
              $('#controller').click(postProficiencyUserAction);
  
  
  
          }
          var postProficiencyUserAction = function () {
              //var token = $('[name=__RequestVerificationToken]').val();
              var headers = {};
              //headers["__RequestVerificationToken"] = token;
              //var userAction = { createdOn: "2013-05-21T00:00:00", userId: "12345678-1234-1234-1234-000000000001", actionId: "12345678-1234-1234-1234-000000000003" };
              $.ajax({
                  type: 'POST',
                  url: 'http://localhost:58755/api/values',
                  cache: false,
                  headers: headers,
                  contentType: 'application/json; charset=utf-8',
                  data: 'test',
                  dataType: "json",
                  success: function () {
  
                  },
                  error: function () {
  
                  }
              });
          };
          function onNewMessage(message) {
              // ... todo: validation !!!! :)
              $('#messages').append('&lt;li&gt;' + message + '&lt;/li&gt;');
          };
  
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div&gt;
          &lt;h2&gt;Chat&lt;/h2&gt;
          &lt;input type="button" id="controller" value="Controller Method" /&gt;
          &lt;div&gt;
              &lt;h2&gt;Message(s) Received&lt;/h2&gt;
              &lt;ul id="messages"&gt;&lt;/ul&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Nothing fancy.  Whenever the connected hub receives a new message, a new item is added to the unordered list.  There is a button that makes an Ajax call into the ValuesController post method.</p>
  
  <pre><code>public class ValuesController : ApiController
  {
      // POST api/values
      public void Post([FromBody]string value)
      {
          var hubContext = GlobalHost.ConnectionManager.GetHubContext&lt;ChatHub&gt;();
          hubContext.Clients.Group("TestGroup").send("TestGroup", "Called from Controller");
      }
  </code></pre>
  
  <p>The Hub call does not work.  An error is not thrown, but, the message is never received.  Putting a breakpoint in the "Send" method of the Hub does not work either.  I feel like I am doing it right.  Anyone help?  Again, source code can be found <a href="https://skydrive.live.com/redir?resid=EDAFB4DBECFEE2EA!23072&amp;authkey=!AJSMQJ0RzAPlz3Y" rel="noreferrer">here</a></p>