1

I am new to using Azure signalR service and I am kinda confused about something.

The thing is I am using a .Net 4.8 client and a javascript client with a self-hosted hub.

For the .net client this is the code:

using Microsoft.AspNet.SignalR.Client;
{
    public class SignalRHub : ISignalRHub
    {
        private const string HubName = "Hub";
        private readonly IHubProxy hub;
        private readonly HubConnection connection;

        public SignalRHub(string signalRUrl)
        {
            connection = new HubConnection(signalRUrl);
            connection.StateChanged += Connection_StateChanged;
            hub = connection.CreateHubProxy(HubName);
            connection.Start().Wait();
        }
        private void Connection_StateChanged(StateChange obj)
        {
            ...
        }

        public void Refreshed(string userId, string mId)
        {
                    hub.Invoke("refreshed", uId, mId);
        }
    }
}

the signalRUrl is like this "http://localhost:8081/signalr"

The hub startup file is implemented as follows:

        {
            var hubConfiguration = new HubConfiguration
            {
                EnableDetailedErrors = true,
            };

            // Any connection or hub wire up and configuration should go here
            app.MapSignalR("/signalr", hubConfiguration);
 }

And this is the hub file

using Microsoft.AspNet.SignalR;

{
    public class Hub: Hub
    {
        public void Refreshed(string userId, string mId )
        {
            Guid userIdAsGuid;
            if (Guid.TryParse(userId, out userIdAsGuid))
            {
                Clients.Group(userId).Refresh(mId);
            }
        }

        public void JoinGroup(string groupName)
        {
            Groups.Add(Context.ConnectionId, groupName);
        }
    }
}

The code above is working just fine and I have no problem with it. My issue is when I wanted to migrate to Azure SignalR service. I used this doc https://learn.microsoft.com/en-us/azure/azure-signalr/signalr-quickstart-dotnet

I changed the startup code to

 app.MapAzureSignalR(this.GetType().FullName, hubConfiguration);

And I added the endpoints, and for the javascript client, I updated it to jquery.signalR-2.4.1 and it is working fine(sockets are being created)

However, for the .net client-side there was no indication whether to change and if it is really compatible with it.

So what I currently have is a half working application: the javascript side works and sends requests to the azure Signalr service (it can use JoinGroup) however there is no response and the .net client-side doesn't seem to be communicating with the hub(on Azure SignalR service platform no new clients are being added)

Since I am new to this concept I believe I might have missed some points probably due to a compatibilities issue, so I will be grateful for any clarification on this subject.

Thank you

harushi99
  • 23
  • 5
  • Have you added the `Azure:SignalR:ConnectionString` connection string? – stuartd Nov 17 '21 at 16:42
  • @stuartd yes I did add it to the project where the hub is hosted – harushi99 Nov 17 '21 at 16:57
  • You don't need the Azure SignalR service if you're hosting your own signal in a web app. – GH DevOps Nov 17 '21 at 16:59
  • @GH DevOps can you please elaborate more? One of the developers suggested using the Azure SignalR service for scalability purposes instead of self-hosting Signalr – harushi99 Nov 17 '21 at 17:03
  • If you're going to use Azure, remove the app.MapSignalR from Startup.cs. Are you saying in your SignalRHub constructor that connection.Start().Wait() isn't connecting? – GH DevOps Nov 17 '21 at 17:49
  • 1
    Careful; I don't think that your net-framework signalr compatible client will work with your proposed net-core signalr server. See https://learn.microsoft.com/en-us/aspnet/core/signalr/version-differences?view=aspnetcore-6.0 and make sure that both ends of what you have are compatible – Caius Jard Nov 17 '21 at 18:17
  • @GHDevOps yes I already changed app.MapSignalR to app.MapAzureSignalR, according to the documentation, and yes the connection.Start() doesn't seems to be working – harushi99 Nov 18 '21 at 12:59
  • 1
    @CaiusJard, I actually read the documentation and honestly, I am a little bit confused because I also saw this https://devblogs.microsoft.com/dotnet/azure-signalr-service-now-supports-asp-net/ – harushi99 Nov 18 '21 at 13:52

1 Answers1

1

So I figured out what was the issue it seems there were a package incompatibility between .net v4.7 and .net v4. I migrated all packages to following :

  • package id="Microsoft.AspNet.SignalR" version="2.4.1" targetFramework="net48"
  • package id="Microsoft.Azure.SignalR.AspNet" version="1.13.0" targetFramework="net48"
  • package id="Microsoft.AspNet.SignalR.Client" version="2.4.2" targetFramework="net48"

Thank you all for your help.

harushi99
  • 23
  • 5