I am using signalR version 2.1.2. And I am using console application as a SignalrClient. I invoke a method-A and after getting response , I have to invoke method-B based on the response from method-A. In this scenario I am able to successfully invoke and not getting any response from method-B. Whats my mistake??. Here 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 am not getting any response from 'method-B'. Thanks.
The best way to get the result from the SignalR server method is to read its return value instead of invoking a client method at the caller side. For example, you may read the response from the method-A as follows:
Expecting the signature of method-A is something like:
This way you don't have to invoke a client method just to return the result of a server method to the caller. You may invoke another server method from the callback of another server method call like this:
Assumes that method-B returns a string value at the server side.