C# client follows the SignalR client guides https://learn.microsoft.com/aspnet/core/signalr/dotnet-client?view=aspnetcore-6.0&tabs=visual-studio#connect-to-a-hub
As similar to how we do it in the javascript client, in C#, if you have the below method defined in your function ( sample here https://github.com/aspnet/AzureSignalR-samples/tree/main/samples/BidirectionChat):
[FunctionName(nameof(SendToGroup))]
public async Task SendToGroup([SignalRTrigger]InvocationContext invocationContext, string groupName, string message)
{
await Clients.Group(groupName).SendAsync(NewMessageTarget, new NewMessage(invocationContext, message));
}
Or if you are using isolated worker process(sample here https://github.com/aspnet/AzureSignalR-samples/tree/main/samples/DotnetIsolated-BidirectionChat):
[Function("SendToGroup")]
[SignalROutput(HubName = "Hub")]
public SignalRMessageAction SendToGroup([SignalRTrigger("Hub", "messages", "SendToGroup", "groupName", "message")] SignalRInvocationContext invocationContext, string groupName, string message)
{
return new SignalRMessageAction("newMessage")
{
GroupName = groupName,
Arguments = new object[] { new NewMessage(invocationContext, message) }
};
}
The client-side invoke this method by calling InvokeAsync
:
var connection = new HubConnectionBuilder().WithUrl("http://localhost:7071/api").Build();
await connection.StartAsync();
await connection.InvokeAsync("SendToGroup", "group1", "message1");
Also don't forget to setup the Upstream settings in your service (as described in the sample provided) so that the service can pass the call to your azure function.