Call the signalR method in the client method


Suresh

I am using SignalR version 2.1.2. I am using a console application as SignalrClient. I call method A, and after getting the response, I have to call method B based on the response from method A. In this case, I am able to successfully call method B without getting any response. what is my fault? this is my code

var hubConnection = new HubConnection("Url");

IHubProxy proxy = hubConnection.CreateHubProxy("HitProxy");
proxy.On<bool>("Client-method-B", (retvAl) =>
{
    Console.WriteLine("Method-B response");
});

proxy.On<bool>("Client-method-A", (isConnected) =>
{
    Console.WriteLine("Method-A response");
    if(isConnected)
    {
        proxy.Invoke("method-B", "someValue").Wait();
    }
});

hubConnection.Start().Wait();
proxy.Invoke("method-A", "123").Wait();

Here, I don't get any response from "Method B". thanks.

Xmindz

The best way to get results from a SignalR server method is to read its return value rather than calling a client method on the caller side. For example, you can read the response from method-A like this:

proxy.Invoke("method-A", "123").ContinueWith((t) =>
{
  bool isConnected = t.Result;
});

The signature of method A is expected to be something like this:

public bool method-A(string p);

This way, you don't have to call the client method in order to return the result of the server method to the caller. You can call another server method from a callback called by another server method like this:

proxy.Invoke("method-A", "123").ContinueWith((t) =>
{
  bool isConnected = t.Result;
  if(isConnected)
  {
    proxy.Invoke("method-B", "someValue").ContinueWith((u) =>
    {
      Console.WriteLine("Method-B response: " + u.Result);
    });
  }
});

Suppose method B returns a string value on the server side.

Related


Call the signalR method in the client method

Suresh I am using SignalR version 2.1.2. I am using a console application as SignalrClient. I call method A, and after getting the response, I have to call method B based on the response from method A. In this case, I am able to successfully call method B with

SignalR doesn't call client method

Scott So I've read all the other SO questions about this, but it seems like everything should be set up correctly. I'm running a self-hosted SignalR console application that has an empty Hub claim (this is for one-way communication from the server to the conne

Call SignalR Client method from normal C# class

Ravi Mittal I am trying to add SignalR in my MVC project . I need to call SignalR client methods from my class library. I did the following code public class CommomHubManager : ICommomHubManager { readonly IHubContext Context; public Commom

Call SignalR Client method from normal C# class

Ravi Mittal I am trying to add SignalR in my MVC project . I need to call SignalR client methods from my class library. I did the following code public class CommomHubManager : ICommomHubManager { readonly IHubContext Context; public Commom

SignalR client method not getting triggered

Barra I am trying to use SignalR 2.4.1 in Asp.Net MVC, I have done the sample code below, I am using WithGenerateProxy to make the connection. Call the hub method on the server side, receive the login on the client side [18:56:10 GMT+0530 (India Standard Time)

SignalR client method not getting fired

Barra I am trying to use SignalR 2.4.1 in Asp.Net MVC, I have done the sample code below, I am using WithGenerateProxy to make the connection. Call the hub method on the server side, receive the login on the client side [18:56:10 GMT+0530 (India Standard Time)

SignalR cannot call method on server

Ben Black I'm using AngularJS to create a SignalR service that connects to a hub I specify and exposes .onand .invokemethods so that my controllers can listen to events from the server and call methods on the server. Here is the relevant part of my service:

SignalR cannot call method on server

Ben Black I'm using AngularJS to create a SignalR service that connects to a hub I specify and exposes .onand .invokemethods so that my controllers can listen to events from the server and call methods on the server. Here is the relevant part of my service:

SignalR cannot call method on server

Ben Black I'm using AngularJS to create a SignalR service that connects to a hub I specify and exposes .onand .invokemethods so that my controllers can listen to events from the server and call methods on the server. Here is the relevant part of my service:

SignalR cannot call method on server

Ben Black I'm using AngularJS to create a SignalR service that connects to a hub I specify and exposes .onand .invokemethods so my controllers can listen to events from the server and call methods on the server. Here is the relevant part of my service:

SignalR cannot call method on server

Ben Black I'm using AngularJS to create a SignalR service that connects to a hub I specify and exposes .onand .invokemethods so my controllers can listen to events from the server and call methods on the server. Here is the relevant part of my service:

SignalR - Client method not called when user is not authorized

Flacco It's just that I have the annotations section, when I post some annotations to the database, signalr calls a method on all clients. var hub = GlobalHost.ConnectionManager.GetHubContext<NotificationsHub>(); hub.Clients.All.updateBlogComments(Mapper.Map<B

No client method with name 'x' found in SignalR

Film I have an ASP.NET Boilerplate v3.6.2 project (.NET Core/Angular) where I need to call client functions from backend methods, so I am using the ASP.NET Core SignalR implementation . I followed the official documentation, so: in the backend In my module I a

SignalR - Client method not called when user is not authorized

Flacco It's just that I have the annotations section, when I post some annotations to the database, signalr calls a method on all clients. var hub = GlobalHost.ConnectionManager.GetHubContext<NotificationsHub>(); hub.Clients.All.updateBlogComments(Mapper.Map<B

SignalR - Client method not called when user is not authorized

Flacco It's just that I have the annotations section, when I post some annotations to the database, signalr calls a method on all clients. var hub = GlobalHost.ConnectionManager.GetHubContext<NotificationsHub>(); hub.Clients.All.updateBlogComments(Mapper.Map<B

SignalR JS client: pass parameter to invoke method

dafriskymonkey I'm trying to write a function inside an object that appHubwill call a method on the server. Here is my code: var connection = $.hubConnection(); var appHubProxy = connection.createHubProxy('appHub'); var appHub = { //some methods here

SignalR JS client: pass parameter to invoke method

dafriskymonkey I'm trying to write a function inside an object that appHubwill call a method on the server. Here is my code: var connection = $.hubConnection(); var appHubProxy = connection.createHubProxy('appHub'); var appHub = { //some methods here

SignalR - Client method not called when user is not authorized

Flacco It's just that I have the annotations section, when I post some annotations to the database, signalr calls a method on all clients. var hub = GlobalHost.ConnectionManager.GetHubContext<NotificationsHub>(); hub.Clients.All.updateBlogComments(Mapper.Map<B

SignalR - Client method not called when user is not authorized

Flacco It's just that I have the annotations section, when I post some annotations to the database, signalr calls a method on all clients. var hub = GlobalHost.ConnectionManager.GetHubContext<NotificationsHub>(); hub.Clients.All.updateBlogComments(Mapper.Map<B

No client method with name 'x' found in SignalR

Film I have an ASP.NET Boilerplate v3.6.2 project (.NET Core/Angular) where I need to call client functions from backend methods, so I am using the ASP.NET Core SignalR implementation . I followed the official documentation, so: in the backend In my module I a

SignalR JS client: pass parameter to invoke method

dafriskymonkey I'm trying to write a function inside an object that appHubwill call a method on the server. Here is my code: var connection = $.hubConnection(); var appHubProxy = connection.createHubProxy('appHub'); var appHub = { //some methods here