System.Net.Http.HttpRequestException was caught + when I try to make SignalR hubConnection

Please help me. I keep getting a System.Net.Http.HttpRequestException exception when I try to create a hubConnection. I went through a lot of tutorials and downloaded code samples, and nothing works. I also tried to find ways to configure my computer on the Internet, but it is too confusing. Any suggestion would be welcome.

InnerException: the connection could not be completed because the target machine actively refused it enter image description here

Note: on the local host, every thing works fine

My asp.net C # server application running on IIS servers running on a Live server. can access any place.

Follow the ASP.NET application code on the ASP.NET server side

The code for Index.aspx is here:

<html xmlns="http://www.w3.org/1999/xhtml"> <head > <title>SignalR Echo</title> <script src="Scripts/jquery-1.6.4.min.js"></script> <script type="text/javascript" src="Scripts/jquery.signalR-2.1.2.min.js"></script> <script type="text/javascript" src="Scripts/jquery.signalR-2.1.2.js"></script> <script src='<%: ResolveClientUrl("~/myhubs/hubs") %>'></script> </head> <body> <form id="form1" runat="server"> <script type="text/javascript"> function htmlEncode(value) { return $("<div/>").text(value).html(); } function addMsg(msg) { $("#messages").append("<li>" + htmlEncode(msg) + "</li>"); } $(function () { var chatHubProxy = $.connection.myChatHub; chatHubProxy.client.appendNewMessage = function (clientName, message) { addMsg(clientName + ": " + message); }; // Start the hub connection addMsg("Connecting Hub..."); $.connection.hub.url = "/myhubs" $.connection.hub.logging = true; $.connection.hub.start().done(function () { addMsg("Server is running now."); $("#send").click(function () { chatHubProxy.server.broadcastMessage("Server: ", $("#msg").val()); }); }).fail(function () { addMsg("Server is not running."); }); }); </script> <table> <tr> <td><span>Message:</span></td> <td> <input type="text" id="msg" /> </td> <td> <input type="button" value="Send" id="send" /> </td> <td> &nbsp;</td> <td /> </tr> </table> <ul id="messages"></ul> </form> </body> </html> 

The code for Mychathub.cs is here:

 using Microsoft.AspNet.SignalR; using System; namespace SignalRHubServer { /// <summary> /// The client must use camel-cased names to RPC this Hub and its methods. /// JS Example: /// var chatHub = $.connection.myChatHub; /// chatHub.server.broadcastMessage("dzy", "Hello all!"); /// </summary> public class MyChatHub : Hub { public async Task BroadcastMessage(string callerName, string message) { // Case-insensitive when the server RPC the client methods await Clients.All.appendnewmessage(callerName, message); } } } 

The startup.cs code is here:

 using Microsoft.Owin; using Owin; using Microsoft.AspNet.SignalR; [assembly: OwinStartup(typeof(SignalRHubServer.Startup))] namespace SignalRHubServer { public class Startup { public void Configuration(IAppBuilder app) { app.MapSignalR("/myhubs", new HubConfiguration()); //app.MapSignalR(); } } } 

My client side I use a console application and this is a console application that I run on another PC.

here is my Client.cs code:

 using Microsoft.AspNet.SignalR.Client; using Microsoft.AspNet.SignalR.Client.Hubs; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SignalRHubClient { class Program { static void Main(string[] args) { try { string inputLine; var hubConn = new HubConnection("http://xxx.xxx.xxx.11:8080/myhubs"); var chatHubProxy = hubConn.CreateHubProxy("myChatHub"); chatHubProxy.On("appendNewMessage", delegate(string name, string message) { Console.WriteLine("{0}: {1}", name, message); }); hubConn.Start().Wait(); Console.WriteLine("Success! Connected with client connection id {0}", hubConn.ConnectionId); if (hubConn.ConnectionId != null) { string abd = "Tariq"; while (!string.IsNullOrEmpty(inputLine = Console.ReadLine())) { chatHubProxy.Invoke("broadcastMessage", abd, inputLine).Wait(); } } } catch (Exception ex) { Console.WriteLine(ex.Message.ToString(), "ERROR"); Console.ReadLine(); } Console.ReadLine(); } } } 

I get an exception in the client console application. when the bellow method is called. Note: a catch point on the catch line is required.

hubConn.Start (). Wait ();

+5
source share

Source: https://habr.com/ru/post/1200673/


All Articles