SignalR self hosted windows service, listening for messages

前端 未结 1 1814
再見小時候
再見小時候 2021-01-06 04:50

I\'m attempting to build a windows service that\'s self-hosting SignalR.

I have read through tutorials such as SignalR Self-Host on ASP.Net

I\'m noticing tha

相关标签:
1条回答
  • 2021-01-06 05:13

    In general SignalR offers a real-time messaging environment with the benefit that it can push messages to clients without them requesting the update (you've read the intro, so enough for that). Whether you start your self-host from within a service shouldn't make a difference.

    From what I understand from your scenario: You need to consume the messages from the self-hosted service. I think you might only need a hint to the SignalR Desktop Client. I think your app/service should start off the service and then act as a client to the service itself. This would be the cleanest approach.

    As the javascript client it acts as a consumer of the service with the same capabilities:

    HubConnection conn = new HubConnection("http://192.168.1.1:8080");
    IHubProxy hub = conn.CreateHubProxy("ChatHub");
    
    // call from hub to client
    hub.On<string, string>("addMessage", (name, message) =>
    {
         // Handle incoming data update
    });
    

    and vice versa from the desktop client to the hub:

    await hub.Invoke<string, string>("Send", name, message);
    

    To work with groups, the logic needs to be defined within your hub. The documentation Working with groups gives an understandable overview.

    0 讨论(0)
提交回复
热议问题