简体   繁体   中英

Signalr response from client

How do I get the result into my action from my subscribed client?

I have setup hub in my mvc application with signalr with purpose to validate clients between multiple clients providers.

which I am accessing in my controller as:

IHubContext _hubContext = GlobalHost.ConnectionManager.GetHubContext<AmsHub>();

and my mvc action

  public ActionResult Index()
    {
        var result = _hubContext.Clients.All.FindUsers("johny brown");
// how do I access the result?
        return View();
    }

My subscribed client ( I have multiple ) with implementation

 var hubConnection = new HubConnection(hubUrl);
 IHubProxy myHubProxy = hubConnection.CreateHubProxy("AmsHub");


 myHubProxy.On("FindUsers", (name) =>
      {
         var foundRecords = new User()
          {
             FirstName = "Johny",
             LastName = "Brown",
             Email = "johny.brown@dummy.com",
          };
     });

There is no return values in SignalR (from Client to Server). You can define a FindUsersCallback function and call it at your Client. On Server side you handle this "Signal" and give your View() back.

myHubProxy.On("FindUsers", (name) =  > {
        var foundRecords = new User() {
            FirstName = "Johny",
            LastName = "Brown",
            Email = "johny.brown@dummy.com",
        };

        hubConnection.asmHub.FindUsersCallback(foundRecords);
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM