当我尝试创建SignalR hubConnection时,遇到了System.Net.Http.HttpRequestException

Ada*_*dam 5 asp.net signalr

请帮助我,当我尝试创建hubConnection时,我不断收到System.Net.Http.HttpRequestException.我已经完成了许多教程并下载了示例代码,似乎没有任何工作.我也尝试在线搜索配置我的计算机的方法,但它太快得令人困惑.任何建议都将受到欢迎.

InnerException:无法建立连接,因为目标计算机主动拒绝它 在此输入图像描述

注意:在localhost上,每件事都可以正常工作

我的asp.net c#服务器应用程序在IIS上运行.在Live服务器上运行.可以访问任何地方.

遵循asp.net C#服务器端应用程序的代码

Index.aspx代码在这里:

 <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>
Run Code Online (Sandbox Code Playgroud)

Mychathub.cs代码在这里:

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's methods
            await Clients.All.appendnewmessage(callerName, message);
        }


    }
}
Run Code Online (Sandbox Code Playgroud)

startup.cs代码在这里:

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();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我的客户端我正在使用控制台应用程序和我在另一台PC上运行的控制台应用程序.

这是我的Client.cs代码:

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();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我在客户端控制台应用程序中遇到异常.当波纹管方法被调用时.注意:在捕获线上需要断点.

hubConn.Start()等待();