2

我正在尝试在 .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>
4

1 回答 1

0
  1. 当任务没有出现故障时,您可能希望订阅任务继续的事件。
  2. 如果您已成功连接到服务器,您可能希望使用 fiddler 来跟踪服务器消息。
  3. 确保您的事件处理程序包含参数(如果有),用于从服务器发送的参数。您的应用程序可能会收到消息但处理错误。
于 2013-02-18T12:55:34.460 回答