Как интегрировать push-уведомления в Angular 7, используя signalR и API в C #? - PullRequest
0 голосов
/ 01 апреля 2019

У меня есть приложение Angular 7, в котором я хочу реализовать push-уведомление, используя SignlaR (версия 2.4.4) с API в C #. Может кто-нибудь предложить любую Документацию к нему или любой пример кода, который может помочь мне решить мою проблему.

Я перепробовал все, что могу, но не могу установить соединение между клиентом Angular SignalR и SignalR Hub, созданным в C # API.

 1)This is my Startup.cs 
        HubConfiguration cfg = new HubConfiguration();
        app.MapSignalR<PersistentConnection>("/ClientHub");
        app.MapSignalR(cfg);
 2)This is my Hub
        public class ClientHub : Hub
       {
         public Task SendNotificationCount(int chatUserCnt)
         {
           var context = 
           GlobalHost.ConnectionManager.GetHubContext<ClientHub>();
           return context.Clients.All.SendAsync("Send", chatUserCnt);
         }

         public Task SendHelloToAll(string message)
         {
            var context = 
            GlobalHost.ConnectionManager.GetHubContext<ClientHub>();
            return context.Clients.All.SendMsgAsync("SendToAll", message);
          }

        }
   3)This is Angular Code from there i am trying to Connect to Hub.
       hubUrl = http://localhost:60067/ClientHub
       connectToHub(hubUrl:string){

       this.connection = new 
       HubConnectionBuilder().withUrl(hubUrl).build();

       this.connection.start().then(() => {
       console.log("connected to hub");
       this.connection.on('SendToAll', (message) => { 
       alert(message);
       });
       }).catch((error) => {
        console.log(error);
       });


      }


 I am expecting, whenever there is change in Database for notification i 
 want to get that alerts through Hub realtime.
 Also i want to send database changes using signalR hub to angular.
 But i am not able to connect with hub from angular.

1 Ответ

0 голосов
/ 01 апреля 2019
...