Signal R Connection Get 500 response On AWS ec2

10/21/2017

i have two applications

  • Web api Core
  • Web application Angularjs

from web api app i want to push notification to web app so iused

hubConnection = new HubConnection(_config["APIRoot:url"], useDefaultUrl: false);
   hub = hubConnection.CreateHubProxy("TaskHub");

to push a message for example to all clients , it works fine on my local machine also i deployed my two app to a local server (windows) and it works fine

note: local server links

  • Web api Core(192.168.100.30:8080)
  • Web application Angularjs(192.168.100.30:8181)

then we deploy to aws ec2 server as beta server using (Kubernates) with following links :

  • Web api Core(ms-qa.mycompany.com/api)
  • Web application Angularjs(ms-qa.mycompany.com)

i got the following error in console enter image description here

but some times it working (not stable)

iam using angular js factory in web app

BOAApp.factory('signalRService', ['$http', '$q', 'urlRoot', 'httpService', '$cookies',
function ($http, $q, urlRoot, httpService, $cookies) {
    var hubConnection;
    var hub;

    var signalR = {
        hubStart: function () {                
            var token = "";
            var authData = $cookies.get('authorizationBOAAppData');            
           // hubConnection = $.hubConnection(urlRoot);
            hubConnection = $.hubConnection(urlRoot +"/signalr", {
                useDefaultPath: false
            });
            hub = hubConnection.createHubProxy('taskHub');
            if (authData) {
                authData = JSON.parse(authData);
                token = authData.authInfo.token;//'Bearer ' +
            }
            hubConnection.qs = { 'auth_token': token };
            hubConnection.logging = true;

            var def = $q.defer();
            hubConnection.start({ withCredentials: false }).done(function () {
               // hub.invoke('join');
                console.log("Hub started");
                def.resolve("hub started successfully started");

            }).fail(function (error) {
                console.log(error);
                def.reject("hub conniction faild to start");
            });
            //---- Connection Events -----//
            hub.connection.error(function (error) {
                if (error)
                    console.log("An error occurred: " + error.message);
                self.hub = null;
            });
            hub.connection.disconnected(function (error, callback) {

                console.log("Connection lost. " + error);

                // IMPORTANT: continuously try re-starting connection
                setTimeout(function () {
                    hubConnection.start({ withCredentials: false }).done(function () {
                        //if (callback)
                        //    callback();
                    //    hub.invoke('join');
                        console.log("Hub started");
                    });
                    console.log("setTimeout Hub Connect");
                }, 1000);
            });
            hub.connection.stateChanged(function (change) {
                if (change.newState === $.signalR.connectionState.reconnecting) {
                    console.log('Re-connecting');
                }
                else if (change.newState === $.signalR.connectionState.connected) {
                    console.log('The server is online');
                }
                else if (change.newState === $.signalR.connectionState.connecting) {
                    console.log('The server is connecting');
                } else if (change.newState === $.signalR.connectionState.disconnected) {
                    console.log('The server is disconnected');
                }
            });
            //--- End Connection Events -//
            return def.promise;
        },
        state: function () {
            // connecting: 0, connected: 1, reconnecting: 2, disconnected: 4
            return hub.connection.state;
        },
        hubProxy: function() {
            return hub;
        },
        hubProxyConnection: function() {
           return hubConnection;
        }
    }

    return signalR;
}]);

Any help would be appreciated!

-- ahmed naguib
.net
amazon-ec2
asp.net-core
kubernetes
signalr

0 Answers