3

I have done a lot of research online but can't find the solution. I have created a SignalR hub on the WebAPI backend and enabled the CORS feature.

I also have a client (Ionic) app try to connect to the SignalR hub for real-time chat. The problem is that when the Hybrid app tries to connect to the SignalR hub, I am getting

The ConnectionId is in the incorrect format.

I am getting OnDisconnected Event on the SignalR Hub BUT not the OnConnected Event!

This is my client code (ionic):

  • localhost:64965/signalr is my SignalR hub
  • SignalR Proxy also generated on localhost:64965/signalr/hubs
var signalr_chatHub = $.connection.ChatHub;

signalr_chatHub.client.welcomeMessage = function (message) {
      console.log('WelcomeMessage', message);
};

$.connection.hub.url = "http://localhost:64965/signalr";
$.connection.hub.logging = true;

$.connection.hub.start().done(function () {
      console.log('signal connection connected');
}).fail(function (err) {
      console.log('Could not Connect!', err);
});

Chrome Console Errors:

chrome console errors

public class ChatHub : Hub<IChat>
{
    public override Task OnConnected()
    {
        var connectionId = Context.ConnectionId;

        return base.OnConnected();
    }

    public override Task OnDisconnected(bool stopCalled)
    {
        var connectionId = Context.ConnectionId;

        return base.OnDisconnected(stopCalled);
    }

    public override Task OnReconnected()
    {
        return base.OnReconnected();
    }

    public void WelcomeMessage()
    {
        Clients.All.NewMessage("Welcome");
    }
}
Maria Ines Parnisari
  • 16,584
  • 9
  • 85
  • 130
Andy Lee
  • 31
  • 2