0

I currently have a WebApp which is using the "classic" SignalR. I am trying to migrate to use Azure Signal R instead.

I know there are a lot of examples out there but I can't figure out how am I suppose to go about it in implementing it. I apologize in advance but I need help.

My question here is that the when I try to fetch the Clients I am getting null reference because the hub is not found. From what I understood the GlobalHost was now removed. I was using this to get the HubContext. I can't figure out how to register and resolve the IHubContext<MyHub> and send the message from server side to client side.

Is there a specific way to register these hubs (server side) because I can't figure out how to do it based on the examples I am finding online and the library I am using, or I am completely off?

Thanks in advance and if I did not provide enough information please ask me.

I upgraded the Nuget packages with Microsoft.AspNet.SignalR 2.4.3 as listed below.

enter image description here

I have this hub

[HubName(nameof(MyHub))]
public class MyHub: Hub
{
        public void SendMessage(string username, string message)
        {
            dynamic client = this.Clients.Group(username);
            client.SendMessage(message);
        }
}

And I changed my startup method to this

public void Configuration(IAppBuilder app)
{
      this.ConfigureAuth(app);

      app.MapAzureSignalR("/signalr", ConfigureSignalR(GlobalHost.DependencyResolver), new Action<ServiceOptions>(ConfigureServiceOptions));
}

public static void ConfigureServiceOptions(ServiceOptions serviceOptions)
{
   string connectionString = ConfigurationManager.ConnectionStrings[SIGNALR_CONNECTION_STRING_NAME].ToString();
            serviceOptions.ConnectionString = connectionString;            
}

public static HubConfiguration ConfigureSignalR(IDependencyResolver resolver)
{
    HubConfiguration hubConfiguration = new HubConfiguration();
    hubConfiguration.EnableDetailedErrors = true;                       
           
            return hubConfiguration;
}

From the client side part I upgrade the library to ASP.NET SignalR JavaScript Library 2.4.3 and using currently using this client side.

var connection = jQuery.hubConnection();
var hubProxy = connection .createHubProxy("MyHub");
hubProxy.on("SendMessage", function(){ .... });
connection.start({ transport: ['webSockets'] }).done( function () 
                {
                    console.log( "Signal R Connection started" );
                } )

  • Refer this [GitHub](https://github.com/aspnet/AzureSignalR-samples/tree/main/aspnet-samples/ChatRoom) Sample code. – Harshitha Aug 25 '23 at 08:16

0 Answers0