1

I have been using the Azure SignalR API just fine for sending messages to groups, everyone and single users.

I have a problem adding a user to a group though.

I execute the request as per https://learn.microsoft.com/en-us/azure/azure-signalr/signalr-quickstart-rest-api#add-user-to-group and while i get a success response, the user is not added to group.

var url = "xxx.service.signalr.net/api/v1/hubs/<hub-name>/groups/<group-name>/users/<userid>"

var request = new HttpRequestMessage(HttpMethod.Put, _azureSignalRUtilities.GetUrl(url));

request.Headers.Authorization = new AuthenticationHeaderValue("Bearer",
            _azureSignalRUtilities.GenerateAccessToken(url, _serverName));
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

I have copied the samples from https://github.com/aspnet/AzureSignalR-samples/tree/master/samples/Serverless

spottedmahn
  • 14,823
  • 13
  • 108
  • 178
mathew
  • 185
  • 4
  • 20
  • What does the response look like? Is it just a "200"? –  Mar 05 '19 at 18:36
  • @Rthomas529 yes 200 Accepted – mathew Mar 06 '19 at 06:17
  • Doublechecked the Method in the request that it is PUT? Any information in the body of repsonse? – JohanSellberg Mar 08 '19 at 14:41
  • @mathew I hope posted answer solves your question – Rahul Ruikar Mar 12 '19 at 03:01
  • @RahulRuikar Thanks for the reply. But still not working. I cant see any change from the original samples. What have you changed? – mathew Mar 12 '19 at 06:49
  • Are you able to run code using repository I posted? “Send group” URL is incorrect in the sample..you need to setup signalR service and use connection string in code from repository I mentioned in the solution. Setup user secret with connection string..how to setup that is mentioned on azure samples page..after this let me know what exactly is not working for you – Rahul Ruikar Mar 12 '19 at 06:56
  • Also in my example I removed other code which is not related to problem like sending to specific user..I changed some URL to reflect correct api – Rahul Ruikar Mar 12 '19 at 06:58

1 Answers1

3

With some changes to the sample application and adding new methods to add/remove users from a group, I am able to add/remove a specific user to the group and send messages to that group.

I have group name hardcoded in this sample as "TestGroup"

Client output

Started 2 client "123" and "456" enter image description here

Server Output

  1. only user "123" is added to group "TestGroup"
  2. Message is sent to group "TestGroup", it was received only by "123"
  3. User "123" is removed from the group.

There was some issue with the sample code. enter image description here

  1. Message is again sent to Group but none of user is part of "TestGroup' and it was not received by any of users. enter image description here

I have modified sample application to add 2 methods for this addusertogroup removeuserfromgroup also corrected "send group "

Note : I found that group name is case-sensitive

complete code is available in this repository https://github.com/rahulruikar/Serverless

spottedmahn
  • 14,823
  • 13
  • 108
  • 178
Rahul Ruikar
  • 1,076
  • 6
  • 9