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