c# - SignalR Error "No connection could be made because the target machine actively refused it" -


i have single page application (spa) angularjs front-end (client) , web api back-end (server). use signalr messaging between client , server. works fine on development machine (with iis express), when deployed server testing, following error when attempting establish connection hub:

exception thrown: system.net.http.httprequestexception: error occurred while sending request. ---> system.net.webexception: unable connect remote server ---> system.net.sockets.socketexception: no connection made because target machine actively refused 127.0.0.1:60161 @ system.net.sockets.socket.endconnect(iasyncresult asyncresult) @ system.net.servicepoint.connectsocketinternal(boolean connectfailure, socket s4, socket s6, socket& socket, ipaddress& address, connectsocketstate state, iasyncresult asyncresult, exception& exception) --- end of inner exception stack trace --- @ system.net.httpwebrequest.endgetresponse(iasyncresult asyncresult) @ system.net.http.httpclienthandler.getresponsecallback(iasyncresult ar) --- end of inner exception stack trace --- @ system.runtime.compilerservices.taskawaiter.throwfornonsuccess(task task) @ system.runtime.compilerservices.taskawaiter.handlenonsuccessanddebuggernotification(task task) @ cmr.messaging.publisherservice.createrequestservice.d__7.movenext() in c:\users...\createrequestservice.cs:line 143

even though connects signalr hub client:

signalr hub connection

the relevant part of client side signalr code (in anglarjs service):

    // setting signalr hub     var hub = new hub("reporthub", {         listeners: {             'newconnection': function (id) {             },             'broadcastreportprogress': function (reportprogress) {                  reports.add(reportprogress[0].clientname, reportprogress[0].folderpath, reportprogress[0].reportname, reportprogress[0].status, reportprogress[0].username);                 $rootscope.$apply();             },             'broadcastusergenerating': function(reportprogress) {                 reports.addactiveuser(reportprogress.clientname, reportprogress.status, reportprogress.username);                 $rootscope.$apply();             }         },         methods: ['send'],         errorhandler: function(error) {             console.error(error);         },         hubdisconnected: function () {             if (hub.connection.lasterror) {                 hub.connection.start();             }         },         transport: 'websockets',         logging: true,         queryparams: { username: authservice.authentication.username },          rootpath: 'http://localhost:60161/signalr'     }); 

the error occurs in following code snippet, in window service attempting establish connection signalr hub (the error line corresponds 'createrequestservice.cs:line 143' in error message above):

        try         {             ilist<reportprogress> generationprogress = new list<reportprogress>();             generationprogress.add(new reportprogress             {                 clientname = clientname,                 folderpath = response.folderpath,                 reportname = response.response,                 status = "inprogress",                 username = response.username             });              var hubconnection = new hubconnection("http://localhost:60161/signalr", false);             ihubproxy reporthubproxy = hubconnection.createhubproxy("reporthub");              **await hubconnection.start(); --> error occurs here**              await reporthubproxy.invoke("sendreportprogress", generationprogress);             await reporthubproxy.invoke("sendusergenerating", generationprogress[0]);         }         catch (exception ex)         {             throw new exception(nameof(this.gettype) + " ****exception**** ", ex);         } 

the signalr hub lives in web api project:

signalr hub location

and here project properties web api project. port number 60161 set. number different port on spa runs because of cross domain compatibility:

apr project properties

any idea why happening?

so after debugging, found problem was. there were, in fact, 2 different issues @ play here. first, since code deployed test server, "localhost" should not used anywhere. instead, url of test server suffix 'signalr' should used, i.e. 'http://testserver.companyname.com/signalr'. second, in client-side signalr hub code had following line:

transport: 'websockets' 

that causing problem because on our test server web sockets not enabled , therefore there no transport use. once commented out line of code, started working, using server side events (sse) transport, web sockets unavailable. after went iis , installed , enabled them, started using web sockets instead of sse. there have it, solution tricky problem. else don't have spend (about) 2 days did figure out.


Comments

Popular posts from this blog

Android volley - avoid multiple requests of the same kind to the server? -

magento2 - Magento 2 admin grid add filter to collection -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -