.NET SignalR客户端无法订阅服务器事件

时间:2012-11-29 20:57:14

标签: .net signalr.client

我正在尝试在.NET客户端中使用SignalR。我能够成功连接但是当我尝试订阅事件时没有任何反应。我无法接收从服务器发送的消息。我是这个领域的新手,所以我不确定我的代码中是否遗漏了某些内容或出了什么问题。

        var hubConnection = new HubConnection(<url>);

        // Hub name from dev code
        var proxy = hubConnection.CreateHubProxy("pidHub");

        // Subscribing to all the events
        proxy.On("SendTransactionUpdate", () => Logger.LogInformation("SendTransactionUpdate ************************"));
        proxy.On("SendMessage", () => Logger.LogInformation("SendMessage ************************"));
        proxy.On("UpdateStatus", () => Logger.LogInformation("UpdateStatus ************************"));
        proxy.On("TransactionUpdate", () => Logger.LogInformation("TransactionUpdate ************************"));


        // This block executes fine
        hubConnection.Start().ContinueWith(task =>
        {
            if (task.IsFaulted)
            {
                Logger.LogInformation("There was an error opening the connection: {0}" + task.Exception.GetBaseException());
            }
            else
            {
                Logger.LogInformation("Connected. *********");
            }
        }).Wait();

        // Call Provision GUID API and returns a valid GUID
        <call API>

        // Downloads EXE on machine
        <download EXE code>

        // Run EXE with -d option
        // EXE uploads results back to the server and server returns some messages through SignalR
        // I want to capture these messages
        <execute EXE on machine>

1 个答案:

答案 0 :(得分:0)

  1. 当任务没有出现故障时,您可能希望在任务继续时订阅该事件。
  2. 如果您已设法连接到服务器,则可能需要使用fiddler来跟踪服务器消息。
  3. 确保您的事件处理程序包含从服务器发送的参数的参数(如果有)。您的应用程序可能会收到消息但处理错误。