I had the same problem, in my example addNotification is a client method:
var hubContext = GlobalHost.ConnectionManager.GetHubContext<SignalR.NotificationsHub>(); hubContext.Clients.addNotification("Text here");
On the client side, you can add code to call the hub method in addNotification:
var notification = $.connection.notificationHub; notification.addNotification = function (message) { notification.addServerNotification(message);
Hub:
[HubName("notificationHub")] public class NotificationsHub : Hub { public void addServerNotification(string message) {
UPDATE: I read your question over and over again, I really cannot find a reason for this. As a rule, hub methods are called from the client side, or I misunderstood you, one way or another, this update. If you want to do a server thing, then notify clients.
[HttpPost] [Authorize] public ActionResult Add(Item item) { MyHubMethodCopy(item); var hubContext = GlobalHost.ConnectionManager.GetHubContext<SignalR.NotificationsHub>(); hubContext.Clients.addNotification("Items were added"); } private void MyHubMethodCopy(Item item) { itemService.AddItem(item); }
source share