locked
Send messages from outside a hub RRS feed

  • Question

  • User-1849651236 posted

    Hello,

    Has anyone been able to get this project to work?

    I have tried it in Mozilla Firefox, Internet Explorer and Microsoft Edge.

    I did not change any of the code.  I have tried clearing all my caches, cookies and temporary files.  I have tried restarting my system.

    It looks like it is supposed to show "Home page loaded at: {DateTime.Now}".  I have not been able to see anything like that.

    I would be interested in knowing if anyone else has made it work or if anyone has any idea of why it would not work.

    Thanks,
    Tony

    Sunday, July 15, 2018 9:34 PM

All replies

  • User61956409 posted

    Hi Tony,

    I checked the sample code in github, and I find that there are not any hub methods defined in NotificationHub.

    namespace SignalRNotify
    {
        public class NotificationHub : Hub
        {
        }
    }

    You can refer to this documentation: "Use hubs in SignalR for ASP.NET Core" to create hub methods and send messages to clients.

    With Regards,
    Fei Han

    Tuesday, July 17, 2018 9:37 AM
  • User-1849651236 posted

    Fei Han,

    The title of this article is Send messages from outside a hub.  The tutorial is presented to show that it is possible to send messages from other places in your app using the IHubContext Service.

    It also says: This article explains how to access a SignalR IHubContext to send notifications to clients from outside a hub.

    Additionally, I have this Hub code in my application and it still displays the server to client messages:

    using Microsoft.AspNetCore.SignalR;
    using System.Threading.Tasks;
    
    namespace  ChinavasionAPI.Hubs
    {
         public class ChvHub : Hub
         {
              public async Task SendMessage(string user, string message)
              {
                   //await Clients.All.SendAsync("ReceiveMessage", user, message);
              }
         }
    }

    That's the whole purpose of that article.

    Somewhere I read that when the server is sending to a client, the Hub class does not need a method.  I will try to find that and post it here.

    Added on 7/17/2018 12:45PM EDST

    These articles talk about not needing a Hub Send method:

    Github

    StackOverflow

    Thanks,
    Tony

    Tuesday, July 17, 2018 3:54 PM