6

I'm using AspNetCore.SignalR 1.1.0 and AspNetCore.SignalR.Client 1.1.0. I have a .NET client (WPF app) that works correctly when connecting to a web application running on localhost, but when I try to connect to the same web application while it's running in a staging environment (IIS on Azure), it fails to complete the handshake. I am new to SignalR and am not able to determine the reason for the failure.

Here is the connection in the .NET client:

//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

Here is the configuration on the web application

//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);
});

I enabled SignalR logging and also had a look using Fiddler, but it seems that the client just stops before the handshake completes.

Here is some logging at the client

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()

It works on a localhost IIS Express in VS, but it looks like the failure is on the client side. When I run the same WPF app in VS debug mode but connected to an identical application version on IIS 10 on Azure, the failure occurs. What did I miss?

How do I determine the cause of the failure to complete the handshake?

UPDATE:

I've managed to determine that there is something network related potentially causing the issue i.e. it works on my home network but not when using the network on site. As I don't own the network where this app is failing I might need to specify requirements to the admin. What are the network requirements for SignalR? and how could I confirm this theory?

Jon
  • 190
  • 2
  • 15
  • Were you able to identify the problem? Having an issue as well, the .NET Client works on my dev environment, but not when deployed to Azure. – Kal Zekdor May 09 '20 at 01:52
  • Ended up updating to SignalR client 3.1.3, resolved. Which meant I had to migrate from ASP.NET Core 2.2 to 3.1, but that needed to happen anyway, so, eh. – Kal Zekdor May 09 '20 at 22:01
  • 1
    I never managed to find the cause.. In my case the client provided a "new" network and the problem went away. Glad you got it sorted... – Jon May 10 '20 at 08:01

0 Answers0