2a054e6733 | ||
---|---|---|
.. | ||
Pages | ||
Properties | ||
wwwroot | ||
ClientInvocationSample.csproj | ||
ClientResultHub.cs | ||
Program.cs | ||
README.md | ||
appsettings.Development.json | ||
appsettings.json |
README.md
Example app that makes use of SignalR Client Invocation
This sample provides regular function Broadcast
and new feature Client Invocation
supported in NET7.0.
Prerequisites
- Requires NET7.0 Preview7 or later SDK/Runtime. Please installed from https://dotnet.microsoft.com/download/dotnet/7.0.
- Requires SDK
Microsoft.Azure.SignalR
version >= 1.19.0-preview1-11052. Myget | Nuget - Require an Azure SignalR Service resource with a connection string.
Usage
-
Set the connection string in the Secret Manager tool for .NET Core.
dotnet restore dotnet user-secrets set Azure:SignalR:ConnectionString "<your connection string>"
-
Confirm you're installing correct package.
dotnet list package
Expected resolved package version is greater than
1.19.0-preview1-11052
.[net7.0]: Top-level Package Requested Resolved > Microsoft.Azure.SignalR 1.* 1.19.0
-
If not, run command to explicitly install the package.
dotnet add package Microsoft.Azure.SignalR --version 1.19.0-preview1-11052 --source https://www.myget.org/F/azure-signalr-dev/api/v3/index.json
-
Start the app
dotnet run
Using client invocation
- Browse to the site with your favorite browser and it will connect with the SignalR Javascript client.
- It creates 2 clients by default. Grab an ID from the connected connections and paste it in the ID text box.
- Press 'Get Message' to invoke a Hub method which will ask the specified ID for a result.
- The client invoked will unlock 'Ack Message' button and you can type something in the text box above.
- Press 'Ack Message' to return the message to the server which will return it to the original client that asked for a result.
Using client invocation with multiple servers
- Run
dotnet run
to start default profile and will serve underhttps://localhost:7243
. Skip this step if you didn't stop it yet. - Open another bash window, run
dotnet run --launch-profile Server1
to start another server and will serve underhttps://localhost:7245
. - Browse the default server site under
https://localhost:7243
. - In any of the iframe update the url to second server chats page
https://localhost:7245/chats
to access from second server. - Press 'Enter' to access. Now you're able to test clients on different servers.
Using broadcast
- Browse to the site with your favorite browser and it will connect with the SignalR Javascript client.
- It creates 2 clients by default.
- Enter some messages in the text box above 'Broadcast'.
- Press 'Broadcast' to send message to all connected clients.
Using client invoation from anywhere with IHubContext
- Browse to the site with your favorite browser and it will connect with the SignalR Javascript client.
- Copy the ID for a connected connection.
- Navigate to
/get/<ID>
in a new tab. Replace<ID>
with the copied connection ID. - Go to the browser tab for the chosen ID and write a message in the Message text box.
- Press 'Ack Message' to return the message to the server which will return it to the
/get/<ID>
request.