1

I'm using MVC 5, Signal R 2.0.1, and WebAPI 2, and have a simple hub set up named ExportHub

public class ExportHub : Hub
{
    public void Send(string name, string message)
    {
        // Call the addNewMessageToPage method to update clients.
        Clients.All.addNewMessageToPage(name, message);
    }
}

I'm attempting to call this from WebAPI so the UI can be updated.

var hubContext = GlobalHost.ConnectionManager.GetHubContext<ExportHub>();

But within hubContext I don't see any reference to Send or addNewMessageToPage. How do I gain access to the methods within the hub?

rross
  • 2,236
  • 11
  • 36
  • 41

2 Answers2

2

You will not be able to call any methods of specified hub. GetHubContext only returns a IHubContext of specified T Hub. Instead of calling Hub methods you should directly invoke method from your web api method to client like

Clients.All.addNewMessageToPage(name, message);
kkocabiyik
  • 4,246
  • 7
  • 30
  • 40
0

Try to make your Send method static, and then call hubContext.Send(string, string)

johnnyRose
  • 7,310
  • 17
  • 40
  • 61
tzm
  • 588
  • 1
  • 12
  • 27