1
votes

I am trying to consume signalR on a website. SignalR is a self hosted service. SignalR url: http://localhost8080:/signalr

Website is running @ http://localhost:31775/

I am getting error on browser console

GET http://localhost:31775/signalr/negotiate?connectionData=%5B%5D&clientProtocol=1.3&_=1442784297380 404 (Not Found)

This error tells me that proxy that the code below is trying to generate is using website url i.e. relative path. However I want to use absolute path where my signalR service is hosted.

AngularJS Factory

app.factory("signalRService", ['$', '$rootScope', function ($, $rootScope) {
    var proxy;
    var connection;

    return {
        connect: function () {
            connection = $.hubConnection();
            proxy = connection.createHubProxy('myHub');
            connection.start();
            proxy.on('addMessage', function (tags) {
                $rootScope.$broadcast('addMessage', tags);
            });
        },
        send: function () {
            proxy.invoke('send');
        },
    };
}]);

I also added javascript reference for this.

<script src="js/jquery.signalR-2.0.3.min.js"></script>

To validate if my self hosting is running file. I checked http://localhost:8080/signalr/hub on browser

enter image description here

1
Have you enabled CORS in your signalR server OWIN setup?Aditya Santoso

1 Answers

0
votes

What you are missing is a bit of configuration of the proxy:

connection = $.hubConnection('http://localhost:8080/signalr');

How to generalize on that piece of code (the url could be an argument of your connect method, or whatever fits your Angular strategy) is up to you.