locked
SignalR 2 Websockets with ASP.NET Core on .NET Framework RRS feed

  • Question

  • User1541189982 posted

    I have an ASP.NET Core application, running on .NET Framework 4.6.2. I managed to run SignalR 2 by using owin-middleware. The issue is that it uses server events, instead of websockets. Is there any setup that can be done, in order to use websockets? 

    In Startup.cs I am calling both app.UseWebSockets()app.UseSignalR2() // custom extension method maps signalR to appbuilder

    If specifying only webSockets transport, it doesn't have any errors, but it does not connect.

    I have used a similar setup using a ASP.NET MVC project, and it worked as expected, this only reproduces when using ASP.NET Core on .NET Framework.

    enter image description here

    I found some similar posts, but I was not able to run it using websockets: Using SignalR on an asp.net Core app that targets the full .NET Framework

    Thursday, August 31, 2017 7:38 PM

All replies

  • User1771544211 posted

    Hi andreispiti,

    Based on the SignalR's wiki document : https://github.com/SignalR/SignalR/wiki/Faq#what-transports-does-signalr-use-in-various-browsers-to-mimic-a-real-time-connection

    The WebSockets transport needs that both the server and browser indicate they can support websockets. So in order to use the websockets transport, you need to make sure that both the client side and server side supports the websockets.

    To verify this, you can set the signalr to only use the Websocket transport to see if it works.

    $.connection.hub.start( { transport: ['webSockets'] });

    And here is a links show the support for websockets on web browsers : https://en.wikipedia.org/wiki/WebSocket

    And note that the WebSocket is introduced in IIS 8, so only the IIS 8.0 or higher can support websockets.

    https://docs.microsoft.com/en-us/iis/get-started/whats-new-in-iis-8/iis-80-websocket-protocol-support

    Best Regards,

    Jean

    Friday, September 1, 2017 3:09 AM
  • User1541189982 posted

    A similar application, using ASP.NET MVC works as expected, so I assume that the issue is because of ASP.NET Core on .NET Framework.

    Friday, September 1, 2017 6:50 AM
  • User1771544211 posted

    Hi andreispiti,

    A similar application, using ASP.NET MVC works as expected, so I assume that the issue is because of ASP.NET Core on .NET Framework.

    Have you tried to set the SignalR to only use the WebSockets transport as I suggested in my above post? Hope the result will shade some light on the root cause of why it not use WebSockets when use ASP.NET Core on .NET Framework.

    $.connection.hub.start( { transport: ['webSockets'] });

    Best Regards,

    Jean

    Monday, September 4, 2017 5:32 AM
  • User1541189982 posted

    If I only use websockets, it does the connect, with 101 response, but it does not start the connection.

    Wednesday, September 6, 2017 9:46 AM
  • User1771544211 posted

    Hi anderipiti,

    I find an issue on GitHub which has the following statement, please check : https://github.com/aspnet/SignalR/issues/435

    Here is a workaround picked from above issue that can be used to fix this issue:

    SignalR 2 isn't supported on ASP.NET Core and SignalR 3 isn't ready yet.

    As you've discovered you can get it running but WebSockets doesn't work. You can get WebSockets to work with a few hacks to SignalR. See here: jkells/SignalR@<tt>58e6b9a</tt>

    And here is a sample: https://github.com/jkells/signalr2-netcore-websockets-sample

    We've been running this hack in production with working WebSockets since January with no issues but YMMV, some features of SignalR might not work.

    Best Regards,

    Jean

    Thursday, September 7, 2017 6:55 AM