SignalR .NET Client无法完成握手

时间:2019-03-30 02:33:41

标签: c# signalr signalr-client

我正在使用AspNetCore.SignalR 1.1.0和AspNetCore.SignalR.Client 1.1.0。我有一个.NET客户端(WPF应用程序),当它连接到在本地主机上运行的Web应用程序时可以正常工作,但是当我尝试在临时环境(Azure上的IIS)中运行时连接到同一Web应用程序时,它无法完成握手。我是SignalR的新手,无法确定失败的原因。

这是.NET客户端中的连接:

//Create the connection
connection = new HubConnectionBuilder()
    .WithUrl(await ClientDataStore.ParseRouteAsync(Routes.POSFullSync), options =>
    {
        options.AccessTokenProvider = async () => await Task.FromResult(await ClientDataStore.GetAccessTokenAsync());
        options.Headers.Add("X-Vending-Outlet-Id", KeyApplicationVariables.VOInstanceId.ToString());
    })
    .ConfigureLogging(logging => {
        logging.SetMinimumLevel(LogLevel.Trace);
        logging.AddConsole();
    })
    .Build();

await connection.StartAsync();
//Fails here with Operation was cancelled

这是Web应用程序上的配置

//Add signalR
services.AddSignalR(hubOptions =>
{
    hubOptions.EnableDetailedErrors = true;
    hubOptions.KeepAliveInterval = TimeSpan.FromMinutes(1);
});

//Configure signalr
app.UseSignalR(routes =>
{
    routes.MapHub<POSFullSyncHub>(Routes.POSFullSync);
    routes.MapHub<POSPartialSyncHub>(Routes.POSPartialSync);
});

我启用了SignalR日志记录功能,也使用了Fiddler,但是客户端似乎在握手完成之前就停止了。

这是客户端的一些日志记录

dbug: Microsoft.AspNetCore.Http.Connections.Client.HttpConnection[18]
      Transport 'WebSockets' started.
info: Microsoft.AspNetCore.Http.Connections.Client.HttpConnection[3]
      HttpConnection Started.
info: Microsoft.AspNetCore.SignalR.Client.HubConnection[24]
      Using HubProtocol 'json v1'.
dbug: Microsoft.AspNetCore.SignalR.Client.HubConnection[28]
      Sending Hub Handshake.
dbug: Microsoft.AspNetCore.Http.Connections.Client.Internal.WebSocketsTransport[13]
      Received message from application. Payload size: 32.
The thread 0x3ca4 has exited with code 0 (0x0).
fail: Microsoft.AspNetCore.SignalR.Client.HubConnection[35]
      Error processing the handshake response.
System.OperationCanceledException: The operation was canceled.
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at System.IO.Pipelines.Pipe.GetReadResult(ReadResult& result)
   at System.IO.Pipelines.Pipe.GetReadAsyncResult()
   at System.IO.Pipelines.Pipe.DefaultPipeReader.GetResult(Int16 token)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at Microsoft.AspNetCore.SignalR.Client.HubConnection.<HandshakeAsync>d__61.MoveNext()
fail: Microsoft.AspNetCore.SignalR.Client.HubConnection[43]
      Error starting connection.
System.OperationCanceledException: The operation was canceled.
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at System.IO.Pipelines.Pipe.GetReadResult(ReadResult& result)
   at System.IO.Pipelines.Pipe.GetReadAsyncResult()
   at System.IO.Pipelines.Pipe.DefaultPipeReader.GetResult(Int16 token)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at Microsoft.AspNetCore.SignalR.Client.HubConnection.<HandshakeAsync>d__61.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.SignalR.Client.HubConnection.<StartAsyncCore>d__47.MoveNext()

它可以在VS中的localhost IIS Express上运行,但看起来故障发生在客户端。当我在VS调试模式下运行相同的WPF应用程序,但在Azure上的IIS 10上连接到相同的应用程序版本时,将发生故障。我想念什么?

如何确定无法完成握手的原因?

更新:

我已设法确定是否存在与网络相关的某些潜在问题,即该问题在我的家庭网络上有效,但在现场使用该网络时无效。由于我不拥有此应用程序无法正常运行的网络,因此可能需要向管理员指定要求。 SignalR的网络要求是什么?我该如何确认这一理论?

0 个答案:

没有答案