WebPubSubServiceClient.AddConnectionToGroup Method asking connection Id

Hariharan Rajkumar 0 Reputation points
2024-06-04T11:07:09.2533333+00:00

I'm using a chat application on Azure Web PubSub. Creating a group so that numerous users can message is what I need.Therefore, I'm using addConnectionToGroup to connect to the group, but it asks for the connection ID and group, so what is the connection ID and how can we produce it? If I supply the client connection token in that method, it returns 401 unauthorized, so I paste the code below.

using Azure.Messaging.WebPubSub;

using static System.Net.WebRequestMethods;

using System.Net; using System.Collections.Generic;

 

MssGetClientAccessUri("Endpoint = https://msgservice.webpubsub.azure.com;AccessKey=NhGuJ+E7T0kWehNzQAMBKmqca7PX+RiIHUC1QTWU9Lk=;Version=1.0;", "Hub24222", "UserIdd", 120, "Group24");  void MssGetClientAccessUri(string ssConnectionString, string ssHub, string ssUserId, int ssTokenLifespan, string groupName) {     var ssAbsoluteUri = "";     var ssErrorMessage = "";

 

    WebPubSubServiceClient service = new WebPubSubServiceClient(ssConnectionString, ssHub);     try     {         IEnumerable<String> roles = [$"webpubsub.sendToGroup.{groupName}"];         var response = service.GetClientAccessUri(TimeSpan.FromMinutes(ssTokenLifespan), ssUserId, roles);         var ssIsSuccess = true;         ssAbsoluteUri = response.AbsoluteUri;         Console.Write(response.AbsoluteUri);         /var ACG = service.AddConnectionToGroup(groupName, response.AbsoluteUri);         Console.Write(ACG.Status);/

 

        var ssStatusCode = 201;     }   catch (Azure.RequestFailedException ex)     {         var ssIsSuccess = false;         var ssStatusCode = ex.Status;         ssErrorMessage = ex.Message;     } }

so how can we achieve this?

Thanks in Advance.

Azure Web PubSub
Azure Web PubSub
An Azure service that provides real-time messaging for web applications using WebSockets and the publish-subscribe pattern.
70 questions
{count} votes