docs/en/Community-Articles/2022-11-23-Signalr-client-results/POST.md
ASP.NET Core 7 supports requesting a result from a client, in this article, we will show you how to use client results with the ABP framework.
public class ChatHub : AbpHub
{
public async Task<string> WaitForMessage(string connectionId)
{
var message = await Clients.Client(connectionId).InvokeAsync<string>("GetMessage");
return message;
}
}
AbpHub that has useful base properties like CurrentUser.WaitForMessage method to call the client's GetMessage method and get the return value.Using
InvokeAsyncfrom a Hub method requires setting the MaximumParallelInvocationsPerClient option to a value greater than 1.
Clients should return results in their .On(...) handlers.
hubConnection.On("GetMessage", async () =>
{
Console.WriteLine("Enter message:");
var message = await Console.In.ReadLineAsync();
return message;
});
connection.on("GetMessage", function () {
const message = prompt("Enter message:");
return message;
});
We can use strongly-typed instead of InvokeAsync by inheriting from AbpHub<T> or Hub<T>:
public interface IClient
{
Task<string> GetMessage();
}
public class ChatHub : AbpHub<IClient>
{
public async Task<string> WaitForMessage(string connectionId)
{
string message = await Clients.Client(connectionId).GetMessage();
return message;
}
}