SignalR-console-app starten muss aufgerufen werden, bevor Daten gesendet werden können

Ich versuche einen client erstellen signalr-app. Derzeit bin ich in der Lage, mein MVC-clients zum senden von Nachrichten zu und von den Hub, aber ich bin vor einige Probleme mit meinem .NET-client-app

Server-Hub-code:

namespace ServerHub
{
    public class ChatterBox : Hub
    {

        public void Send(string message)
        {
            Clients.All.addMessage(message);
        }
    }
}

Console App-code (fast direkt gehoben von github)

using Microsoft.AspNet.SignalR.Client.Hubs;
using ServerHub;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
          Say("hello from console");
        }
        public static void Say(string message)
        {
            //var connection = new HubConnection("http://localhost/");

            //IHubProxy myHub = connection.CreateHubProxy("ChatterBox");

            var connection = new HubConnection("http://localhost/");
            //Make proxy to hub based on hub name on server
            var myHub = connection.CreateHubProxy("ChatterBox");
            //Start connection
            connection.Start().ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    Console.WriteLine("Failed to start: {0}", task.Exception.GetBaseException());
                }
                else
                {
                    Console.WriteLine("Success! Connected with client connection id {0}", connection.ConnectionId);
                    //Do more stuff here
                }
            });

            connection.Send("Hello").ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    Console.WriteLine("Send failed {0}", task.Exception.GetBaseException());
                }
                else
                {
                    Console.WriteLine("Success");
                }
            });
        }
    }
}

Bekomme ich die Fehlermeldung unten, während connection.Send()

Starten muss aufgerufen werden, bevor Daten gesendet werden können.

Wo habe ich bloß falsch gemacht?

EDIT:

2. Versuch:

    var connection = new HubConnection("http://localhost/");
    //Make proxy to hub based on hub name on server
    var myHub = connection.CreateHubProxy("ChatterBox");
    //Start connection
    connection.Start().ContinueWith(task =>
        {
            if (task.IsFaulted)
            {
                Console.WriteLine("Failed to start: {0}", task.Exception.GetBaseException());
            }
            else
            {
                Console.WriteLine("Success! Connected with client connection id {0}",
                                  connection.ConnectionId);

                //Do more stuff here

                connection.Send("Hello");
            }
        });


    myHub.Invoke("Send", "lol");

Immer noch gibt mir eine Fehlermeldung

EDIT: 3. Versuch

            var connection = new HubConnection("http://localhost:60610/");
            //Make proxy to hub based on hub name on server
            var myHub = connection.CreateHubProxy("ChatterBox");
            //Start connection
            connection.Start().ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    Console.WriteLine("Failed to start: {0}", task.Exception.GetBaseException());
                }
                else
                {
                    //Console.WriteLine("Success! Connected with client connection id {0}", connection.ConnectionId);

                    myHub.Invoke("Send", "lol");
                }
            });

Scheint zu funktionieren

Brauchte ich auch, um die port-Nummer, z.B., wenn ich bin Browsen auf meiner MVC-website wie diese: http://localhost:60610/ dies ist die Adresse, die ich brauche, um in meiner console app.

Kann ich sagen, dass während der Bereitstellung, es wird nicht ein Problem sein, weil es standardmäßig port 80?

Schreibe einen Kommentar