From b57dd26dcbf1559233245107e79df499e171f960 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Wed, 23 Nov 2022 16:01:32 +0800 Subject: [PATCH 1/3] Signalr Client results article --- .../2022-11-23-Signalr-client-results/POST.md | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 docs/en/Community-Articles/2022-11-23-Signalr-client-results/POST.md diff --git a/docs/en/Community-Articles/2022-11-23-Signalr-client-results/POST.md b/docs/en/Community-Articles/2022-11-23-Signalr-client-results/POST.md new file mode 100644 index 0000000000..9e6eb5901c --- /dev/null +++ b/docs/en/Community-Articles/2022-11-23-Signalr-client-results/POST.md @@ -0,0 +1,71 @@ +# Signalr Client results + +ASP.NET Core 7 supports [requesting a reuslt from a client](https://learn.microsoft.com/en-us/aspnet/core/release-notes/aspnetcore-7.0?view=aspnetcore-7.0#signalr), in this article will, we will show you how to use client results with the ABP framework. + +## Create a SignalR hub + +```csharp +public class ChatHub : AbpHub +{ + public async Task WaitForMessage(string connectionId) + { + var message = await Clients.Client(connectionId).InvokeAsync("GetMessage"); + return message; + } +} +``` + +* ChatHub inherit from the `AbpHub` which have useful base properties like `CurrentUser`. +* Define `WaitForMessage` method to call the client's `GetMessage` method and get the return value. + +> Using `InvokeAsync` from a Hub method requires setting the [MaximumParallelInvocationsPerClient](https://learn.microsoft.com/en-us/aspnet/core/signalr/configuration?view=aspnetcore-7.0&tabs=dotnet#configure-server-options) option to a value greater than 1. + +## Client + +Clients should return results in their `.On(...)` handlers. + +### .NET Client + +```csharp +hubConnection.On("GetMessage", async () => +{ + Console.WriteLine("Enter message:"); + var message = await Console.In.ReadLineAsync(); + return message; +}); +``` + +### JavaScript client + +```js +connection.on("GetMessage", function () { + + const message = prompt("Enter message:"); + return message; +}); +``` + +## Strongly-typed hubs + +We can use strongly-typed instead of `InvokeAsync` by inheriting from `AbpHub` or `Hub`: + +```csharp +public interface IClient +{ + Task GetMessage(); +} + +public class ChatHub : AbpHub +{ + public async Task WaitForMessage(string connectionId) + { + string message = await Clients.Client(connectionId).GetMessage(); + return message; + } +} +``` + +## See also: + +* [ABP SignalR-Integration documentation](https://docs.abp.io/en/abp/latest/SignalR-Integration) +* [Microsoft client-results documentation](https://learn.microsoft.com/en-us/aspnet/core/signalr/hubs?view=aspnetcore-7.0#client-results) From d3805c3c6f010dd83f8cdbaeb6f8f63ba7c920ee Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Wed, 23 Nov 2022 16:05:20 +0800 Subject: [PATCH 2/3] Update POST.md --- .../2022-11-23-Signalr-client-results/POST.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/Community-Articles/2022-11-23-Signalr-client-results/POST.md b/docs/en/Community-Articles/2022-11-23-Signalr-client-results/POST.md index 9e6eb5901c..a172472207 100644 --- a/docs/en/Community-Articles/2022-11-23-Signalr-client-results/POST.md +++ b/docs/en/Community-Articles/2022-11-23-Signalr-client-results/POST.md @@ -47,7 +47,7 @@ connection.on("GetMessage", function () { ## Strongly-typed hubs -We can use strongly-typed instead of `InvokeAsync` by inheriting from `AbpHub` or `Hub`: +We can use strongly-typed instead of `InvokeAsync` by inheriting from `AbpHub` or `Hub`: ```csharp public interface IClient From 4d2651cf39c1da3d855fe89f0f3cb70b6782427c Mon Sep 17 00:00:00 2001 From: Hamza Albreem <94292623+braim23@users.noreply.github.com> Date: Wed, 23 Nov 2022 11:09:47 +0300 Subject: [PATCH 3/3] quick fix --- .../2022-11-23-Signalr-client-results/POST.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/en/Community-Articles/2022-11-23-Signalr-client-results/POST.md b/docs/en/Community-Articles/2022-11-23-Signalr-client-results/POST.md index a172472207..1f8128ff7c 100644 --- a/docs/en/Community-Articles/2022-11-23-Signalr-client-results/POST.md +++ b/docs/en/Community-Articles/2022-11-23-Signalr-client-results/POST.md @@ -1,6 +1,6 @@ # Signalr Client results -ASP.NET Core 7 supports [requesting a reuslt from a client](https://learn.microsoft.com/en-us/aspnet/core/release-notes/aspnetcore-7.0?view=aspnetcore-7.0#signalr), in this article will, we will show you how to use client results with the ABP framework. +ASP.NET Core 7 supports [requesting a reuslt from a client](https://learn.microsoft.com/en-us/aspnet/core/release-notes/aspnetcore-7.0?view=aspnetcore-7.0#signalr), in this article, we will show you how to use client results with the ABP framework. ## Create a SignalR hub @@ -15,8 +15,8 @@ public class ChatHub : AbpHub } ``` -* ChatHub inherit from the `AbpHub` which have useful base properties like `CurrentUser`. -* Define `WaitForMessage` method to call the client's `GetMessage` method and get the return value. +* ChatHub inherits from `AbpHub` that has useful base properties like `CurrentUser`. +* Define the `WaitForMessage` method to call the client's `GetMessage` method and get the return value. > Using `InvokeAsync` from a Hub method requires setting the [MaximumParallelInvocationsPerClient](https://learn.microsoft.com/en-us/aspnet/core/signalr/configuration?view=aspnetcore-7.0&tabs=dotnet#configure-server-options) option to a value greater than 1.