зеркало из
1
0
Форкнуть 0
AzureSignalR-samples/samples/ClientInvocationSample
Jialin Xin 2a054e6733 minor update. 2022-10-27 16:10:31 +08:00
..
Pages Add sample for client invocation. 2022-10-27 15:35:55 +08:00
Properties Add sample for client invocation. 2022-10-27 15:35:55 +08:00
wwwroot Add sample for client invocation. 2022-10-27 15:35:55 +08:00
ClientInvocationSample.csproj improve README 2022-10-27 16:07:26 +08:00
ClientResultHub.cs Add sample for client invocation. 2022-10-27 15:35:55 +08:00
Program.cs Add sample for client invocation. 2022-10-27 15:35:55 +08:00
README.md minor update. 2022-10-27 16:10:31 +08:00
appsettings.Development.json Add sample for client invocation. 2022-10-27 15:35:55 +08:00
appsettings.json Add sample for client invocation. 2022-10-27 15:35:55 +08:00

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

Usage

  1. Set the connection string in the Secret Manager tool for .NET Core.

    dotnet restore
    dotnet user-secrets set Azure:SignalR:ConnectionString "<your connection string>"
    
  2. 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
    
  3. 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
    
  4. Start the app

    dotnet run
    

client-invocation

Using client invocation

  1. Browse to the site with your favorite browser and it will connect with the SignalR Javascript client.
  2. It creates 2 clients by default. Grab an ID from the connected connections and paste it in the ID text box.
  3. Press 'Get Message' to invoke a Hub method which will ask the specified ID for a result.
  4. The client invoked will unlock 'Ack Message' button and you can type something in the text box above.
  5. 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

  1. Run dotnet run to start default profile and will serve under https://localhost:7243. Skip this step if you didn't stop it yet.
  2. Open another bash window, run dotnet run --launch-profile Server1 to start another server and will serve under https://localhost:7245.
  3. Browse the default server site under https://localhost:7243.
  4. In any of the iframe update the url to second server chats page https://localhost:7245/chats to access from second server.
  5. Press 'Enter' to access. Now you're able to test clients on different servers.

Using broadcast

  1. Browse to the site with your favorite browser and it will connect with the SignalR Javascript client.
  2. It creates 2 clients by default.
  3. Enter some messages in the text box above 'Broadcast'.
  4. Press 'Broadcast' to send message to all connected clients.

Using client invoation from anywhere with IHubContext

  1. Browse to the site with your favorite browser and it will connect with the SignalR Javascript client.
  2. Copy the ID for a connected connection.
  3. Navigate to /get/<ID> in a new tab. Replace <ID> with the copied connection ID.
  4. Go to the browser tab for the chosen ID and write a message in the Message text box.
  5. Press 'Ack Message' to return the message to the server which will return it to the /get/<ID> request.