SignalR总是降级为长轮询

时间:2017-11-13 13:27:25

标签: c# .net websocket signalr

我使用SignalR.Core创建了一个新的Web服务,它正确地协商使用WebSockets。我还将它添加到现有网站,但它无法协商WebSockets和ServerSentEvents,因此将始终降级以使用LongPolling。

两个项目都针对在IIS Express 10上运行的.NET v4.7.1。客户端是使用SignalR.Client库的UWP应用程序。

有谁知道我错过了什么?

客户端:

08:46:25.9067539 - null - ChangeState(Disconnected, Connecting)
08:46:28.4516671 - 1cf03bfa-cfa6-45b2-b3f7-a342c17c8341 - WS Connecting to: ws://192.168.0.84:8080/signalr/connect?clientProtocol=1.4&transport=webSockets&connectionData=[{"Name":"SyncHub"}]&connectionToken=GsZKYTf9rwH3NqngtHe5f6eUEcHRqlGYsBDkC2g43FOZs8zP%2FJg%2Fhld1fdm9iO91yPBoxNIqY7N%2FlnlJDCSfFwK8YTnJNztxRVS5aUPt9G4KrIYEpMNNwyucyHILDMqr
08:46:28.6707519 - 1cf03bfa-cfa6-45b2-b3f7-a342c17c8341 - Auto: Failed to connect to using transport webSockets. System.Exception: Internal server error (500). (Exception from HRESULT: 0x801901F4)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNet.SignalR.Client.Transports.WebSocketTransport.<OpenWebSocket>d__17.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.AspNet.SignalR.Client.Transports.WebSocketTransport.<StartWebSocket>d__16.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.AspNet.SignalR.Client.Transports.WebSocketTransport.<Start>d__14.MoveNext()
08:46:28.7516001 - 1cf03bfa-cfa6-45b2-b3f7-a342c17c8341 - SSE: GET http://192.168.0.84:8080/signalr/connect?clientProtocol=1.4&transport=serverSentEvents&connectionData=[{"Name":"SyncHub"}]&connectionToken=GsZKYTf9rwH3NqngtHe5f6eUEcHRqlGYsBDkC2g43FOZs8zP%2FJg%2Fhld1fdm9iO91yPBoxNIqY7N%2FlnlJDCSfFwK8YTnJNztxRVS5aUPt9G4KrIYEpMNNwyucyHILDMqr
08:46:33.7643871 - 1cf03bfa-cfa6-45b2-b3f7-a342c17c8341 - Auto: Failed to connect to using transport serverSentEvents. System.TimeoutException: Transport timed out trying to connect
08:46:33.7763838 - 1cf03bfa-cfa6-45b2-b3f7-a342c17c8341 - LP Connect: http://192.168.0.84:8080/signalr/connect?clientProtocol=1.4&transport=longPolling&connectionData=[{"Name":"SyncHub"}]&connectionToken=GsZKYTf9rwH3NqngtHe5f6eUEcHRqlGYsBDkC2g43FOZs8zP%2FJg%2Fhld1fdm9iO91yPBoxNIqY7N%2FlnlJDCSfFwK8YTnJNztxRVS5aUPt9G4KrIYEpMNNwyucyHILDMqr
08:46:33.9198908 - 1cf03bfa-cfa6-45b2-b3f7-a342c17c8341 - LP: OnMessage({"C":"d-555200CA-B,0|C,0|D,2","S":1,"M":[]})
08:46:33.9484163 - 1cf03bfa-cfa6-45b2-b3f7-a342c17c8341 - LP Poll: http://192.168.0.84:8080/signalr/poll?clientProtocol=1.4&transport=longPolling&connectionData=[{"Name":"SyncHub"}]&connectionToken=GsZKYTf9rwH3NqngtHe5f6eUEcHRqlGYsBDkC2g43FOZs8zP%2FJg%2Fhld1fdm9iO91yPBoxNIqY7N%2FlnlJDCSfFwK8YTnJNztxRVS5aUPt9G4KrIYEpMNNwyucyHILDMqr&messageId=d-555200CA-B%2C0%7CC%2C0%7CD%2C2
08:46:34.0659311 - 1cf03bfa-cfa6-45b2-b3f7-a342c17c8341 - ChangeState(Connecting, Connected)

服务器:

SignalR.PerformanceCounterManager Error: 0 : Performance counter failed to load: System.InvalidOperationException: The requested Performance Counter is not a custom counter, it has to be initialized as ReadOnly.
   at System.Diagnostics.PerformanceCounter.InitializeImpl()
   at System.Diagnostics.PerformanceCounter..ctor(String categoryName, String counterName, String instanceName, Boolean readOnly)

...

SignalR.Transports.TransportHeartBeat Information: 0 : Connection 1cf03bfa-cfa6-45b2-b3f7-a342c17c8341 is New.
SignalR.Transports.ServerSentEventsTransport Verbose: 0 : Sending outgoing message. Connection id: 1cf03bfa-cfa6-45b2-b3f7-a342c17c8341, transport: ServerSentEventsTransport, message: data: {"C":"d-555200CA-B,0|C,0|D,1","S":1,"M":[]}

SignalR.Transports.ServerSentEventsTransport Verbose: 0 : DrainWrites(1cf03bfa-cfa6-45b2-b3f7-a342c17c8341)
SignalR.Transports.ServerSentEventsTransport Information: 0 : CompleteRequest (1cf03bfa-cfa6-45b2-b3f7-a342c17c8341)
SignalR.Transports.TransportHeartBeat Verbose: 0 : Connection 1cf03bfa-cfa6-45b2-b3f7-a342c17c8341 exists. Closing previous connection.
SignalR.Transports.ServerSentEventsTransport Information: 0 : End(1cf03bfa-cfa6-45b2-b3f7-a342c17c8341)
SignalR.Transports.ServerSentEventsTransport Verbose: 0 : Cancel(1cf03bfa-cfa6-45b2-b3f7-a342c17c8341)
SignalR.Transports.ServerSentEventsTransport Verbose: 0 : DrainWrites(1cf03bfa-cfa6-45b2-b3f7-a342c17c8341)
SignalR.Transports.ServerSentEventsTransport Information: 0 : CompleteRequest (1cf03bfa-cfa6-45b2-b3f7-a342c17c8341)
SignalR.Transports.LongPollingTransport Verbose: 0 : DrainWrites(1cf03bfa-cfa6-45b2-b3f7-a342c17c8341)
SignalR.Transports.LongPollingTransport Information: 0 : CompleteRequest (1cf03bfa-cfa6-45b2-b3f7-a342c17c8341)
Client Connected: 1cf03bfa-cfa6-45b2-b3f7-a342c17c8341
SignalR.Transports.TransportHeartBeat Verbose: 0 : Connection 1cf03bfa-cfa6-45b2-b3f7-a342c17c8341 exists. Closing previous connection.
SignalR.Transports.LongPollingTransport Information: 0 : End(1cf03bfa-cfa6-45b2-b3f7-a342c17c8341)
'iisexpress.exe' (CLR v4.0.30319: /LM/W3SVC/1/ROOT-1-131551227438578638): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Diagnostics.Debug\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Diagnostics.Debug.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
SignalR.HubDispatcher Verbose: 0 : Sending hub invocation result to connection 1cf03bfa-cfa6-45b2-b3f7-a342c17c8341 using transport LongPollingTransport
'iisexpress.exe' (CLR v4.0.30319: /LM/W3SVC/1/ROOT-1-131551227438578638): Loaded 'Microsoft.AspNet.SignalR.Hubs.TypedClientBuilder'. 
SignalR.Transports.LongPollingTransport Verbose: 0 : DrainWrites(1cf03bfa-cfa6-45b2-b3f7-a342c17c8341)
SignalR.Transports.LongPollingTransport Information: 0 : CompleteRequest (1cf03bfa-cfa6-45b2-b3f7-a342c17c8341)
'iisexpress.exe' (CLR v4.0.30319: /LM/W3SVC/1/ROOT-1-131551227438578638): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Collections.Concurrent\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Collections.Concurrent.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
SignalR.Transports.TransportHeartBeat Verbose: 0 : Connection 1cf03bfa-cfa6-45b2-b3f7-a342c17c8341 exists. Closing previous connection.
SignalR.Transports.LongPollingTransport Information: 0 : End(1cf03bfa-cfa6-45b2-b3f7-a342c17c8341)
SignalR.Transports.LongPollingTransport Verbose: 0 : DrainWrites(1cf03bfa-cfa6-45b2-b3f7-a342c17c8341)
SignalR.Transports.LongPollingTransport Information: 0 : CompleteRequest (1cf03bfa-cfa6-45b2-b3f7-a342c17c8341)
'iisexpress.exe' (CLR v4.0.30319: /LM/W3SVC/1/ROOT-1-131551227438578638): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Threading\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Threading.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
SignalR.Transports.TransportHeartBeat Verbose: 0 : Connection 1cf03bfa-cfa6-45b2-b3f7-a342c17c8341 exists. Closing previous connection.
SignalR.Transports.LongPollingTransport Information: 0 : End(1cf03bfa-cfa6-45b2-b3f7-a342c17c8341)
'iisexpress.exe' (CLR v4.0.30319: /LM/W3SVC/1/ROOT-1-131551227438578638): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Globalization\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Globalization.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(1cf03bfa-cfa6-45b2-b3f7-a342c17c8341)
SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(1cf03bfa-cfa6-45b2-b3f7-a342c17c8341)
The thread 0x2ca0 has exited with code 0 (0x0).
The thread 0x151c has exited with code 0 (0x0).
SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(1cf03bfa-cfa6-45b2-b3f7-a342c17c8341)
SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(1cf03bfa-cfa6-45b2-b3f7-a342c17c8341)
SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(1cf03bfa-cfa6-45b2-b3f7-a342c17c8341)
SignalR.Transports.LongPollingTransport Verbose: 0 : DrainWrites(1cf03bfa-cfa6-45b2-b3f7-a342c17c8341)

1 个答案:

答案 0 :(得分:1)

问题是web.config中httpRuntime的目标框架。

设置为<httpRuntime/>。将其更改为<httpRuntime targetFramework="4.7.1"/>可以成功协商websockets。

我终于找到了答案here