【问题标题】:Using SignalR azure service to communicate between 2 angular apps使用 SignalR azure 服务在 2 个 Angular 应用程序之间进行通信
【发布时间】:2019-11-13 20:09:11
【问题描述】:

我在 azure 上有一个 SignalR 集线器,我想用它在两个 Angular 应用程序之间进行简单的聊天(一个在核心中具有后端,而在 .netframework 中具有后端)

到目前为止,我能够(从两个应用程序)连接到集线器并使用该连接在应用程序内进行聊天。 但我无法在另一个应用上触发从一个应用到客户端的事件。

是否存在某种基于正在连接的应用程序的集线器客户端拆分?如果是这样 - 有没有办法禁用它?

(简单地说,我希望任何连接到集线器的客户端(无论他使用的是什么应用程序)都在同一个池中)

不确定这是否重要,但 .netframework 应用使用 hubproxy 而 core 不重要。

【问题讨论】:

    标签: .net angular asp.net-core signalr


    【解决方案1】:

    您可以使用 .Net SignalRClient 在后端之间发送信息

    其中字符串 hubUrl=https://backendUrl.com/yourHub

    public class SignalRClient: ISignalRClient
    {
        private readonly HubConnection _connection;
    
        public SignalRClient(string hubUrl)
        {
            _connection = new HubConnectionBuilder()
                .WithUrl(hubUrl)
                .Build();
        }
    
        public async Task ConnectAsync()
        {
            await _connection.StartAsync();
        }
    
        public async Task DisconnectAsync()
        {
            // await _connection.StopAsync();
            await _connection.DisposeAsync();
        }
    
        public async Task InvokeAsync(string method)
        {
            await _connection.InvokeAsync(method);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-10
      • 1970-01-01
      • 1970-01-01
      • 2021-10-21
      • 1970-01-01
      • 2010-09-29
      • 1970-01-01
      相关资源
      最近更新 更多