Can a windows client connect to a ASP.Net hosted SignalR Server? - signalr

Can a windows client connect to a ASP.Net hosted SignalR Server? Are there any additional configuration steps that would need to be implemented?

Absolutely - we have web and c# clients (Windows + Mono/OSX) that connect with signalR hsoted in AWS (enough buzzwords??).
You can use nuget to obtain .Net client (ASP.NET SignalR .Net client is the one for Windows)
For WebSockets you'll need Win8 on Windows clients, otherwise you'll be using LP/SSE (absoltuely fine in our experience).

Related

Can StreamSocketListener host SignalR?

I have a Universal Windows Platform app running on Windows IoT (ARM) that starts up a web server via StreamSocketListener. I'd like to be able to push content to web browsers via SignalR. There's an enormous number of SignalR nuget packages, but it appears that none of them will work in UWP. Is this correct? If so what is my best option for pushing content down to browsers?
For modern web browsers, SignalR would use Web Sockets for bidirectional communication with the client. You can see if your client browser will support Web Sockets at Can I use.
There is an open source project whose specific goal is providing a Web Socket server in a UWP app. I don't have first-hand experience with the project and it's <1.0 but it mentions compatibility with Windows 10 IoT Core so it may be worth exploring. You can find the project on NuGet here: https://www.nuget.org/packages/IotWeb/
On the client, you can then use the WebSocket object in JavaScript to open a connection with your server.

SignalR not functioning on server

I have a windows service I made through visual studio in c#.
It uses SignalR to connect to a SQl database and receive notifications.
However, when I deploy the service onto the server itself (Windows Server 2008R2), it doesn't function. This server is the server hosting the SQL server too.
This is a SELF-HOSTED SignalR service. It is not using IIS or anything of the like to run. It is packaged as a simple Windows Service. Therefore, it doesn't have issues with typical MVC, IIS hosted apps (such as /signalr/hubs pathing, web.config etc.)
On my development computer, I use the WAN IP of the sql server to connect to its database. When I run it, it does everything it's supposed to and fires off a notification everytime server changes.
On the server itself, the service installs fine, but doesn't fire off any notifications. I left the IP as the WAN IP for developmental services and was planning to change it to localhost, etc. once it works but it does not.
For now, I left the service running on my development computer, and it's working great. I'd really prefer it to be on the server itself though, since that's the computer that will always be online.
Any hints or ideas on why this works on my development computer but not the server?
Thanks!
[Edit]
I'm using Windows 7 with Visual Studio 2013 as my development setup.
The service is running on localhost:2165 (arbitrary port). I am able to access that address via a web browser on the server itself.
You don't state what your development operating system is, but if you are using WebSockets, then you need to have a minimum of Windows 8 or Windows Server 2012.
From the documentation, the supported platforms are (emphasis mine):
Supported server IIS versions
When SignalR is hosted in IIS, the following versions are supported. Note that if a client operating system is used, such as for development (Windows 8 or Windows 7), full versions of IIS or Cassini should not be used, since there will be a limit of 10 simultaneous connections imposed, which will be reached very quickly since connections are transient, frequently re-established, and are not disposed immediately upon no longer being used. IIS Express should be used on client operating systems.
Also note that for SignalR to use WebSocket, IIS 8 or IIS 8 Express must be used, the server must be using Windows 8, Windows Server 2012, or later, and WebSocket must be enabled in IIS. For information on how to enable WebSocket in IIS, see IIS 8.0 WebSocket Protocol Support.

does self hosted signalr require windows server 2012 in order to use websockets?

A self hosted application doesn't seem to run off of IIS, so does it require a specific operating system in order to enable web sockets on the server side?
Browsers will support it because they have implemented the protocol internally, most browsers won't use the operating system transport libraries so they will be able to make use of WebSockets even if the OS does not directly support it.
HTTP.SYS prior to Windows 8/2012 has no built in support for WebSockets, so although .NET 4.5 contains WebSocket classes, they won't work unless you are running .NET 4.5+ on Windows 8/2012 and that will affect self-hosting solutions running in Windows < 8.
The implementation resides in the operating system code that .NET and IIS8 just leverages. The .NET classes simply wrap calls through to HTTP.SYS so it will throw an exception on an operating system that does not have underlying support for it.
When self-hosting you can however use your own internal Web Socket server such as Fleck and tell SignalR that you in fact do support Web Sockets regardless of your OS.
Start a Fleck server in your self-hosted application (examples on their site) and as an example you can do this for a PersistentConnection self-host:
public override Task ProcessRequest(HostContext context)
{
// Override what SignalR will be telling you internally and point to your own Web Socket Server.
context.Items[HostConstants.SupportsWebSockets] = true;
context.Items[HostConstants.WebSocketServerUrl] = "ws://localhost:3000";
return base.ProcessRequest(context);
}
Disclaimer: This is an undocumented feature, the developers of SignalR have told me that this may not be possible in future versions of the library. Keep in mind that you will also need to cater for keep-alives and serializing your data to JSON so it plays nice with the SignalR clients. It still works in version 1.1.3.
I've know for sure that websockets are not supported now by doing a quick test. I created a self hosted hub and then a quick jquery client. On my windows 8 machine the querystring showed websockets, on the server 2008 r2 it showed long polling...
Yes it requires windows server 2012 check the quote below from SignalR Supported Platforms
The SignalR server component can be hosted in the following server or
client operating systems. Note that for SignalR to use WebSockets,
Windows Server 2012 or Windows 8 is required (WebSocket can be used on Windows Azure Web Sites, as long as the site's .NET framework version is set to 4.5, and Web Sockets is enabled in the site's Configuration page).
Also a good read on why can be found here

SignalR won't use Websocket protocol even though I have the protocol installed in windows 8

I'm using signalr to do some real-time events in my web application. I'm trying to force signalr to use the new websocket protocol but it won't, even if I specify it.
$.connection.hub.start({ transport: 'webSockets' })
I definitely have the web socket protocol installed and I am running Windows 8 with IIS 8.
What else do I need to do to enable web sockets support in signalr?
Ensure that your app is using the .NET 4.5 assembly from the SignalR package. If the project is targeting 4.0, or it started that way, then nuget would have added a reference to the 4.0 SignalR assembly which doesn't support websockets. If that's the case, then just uninstall and re-install the signalr packages into your project.
Web Sockets requires .NET 4.5.
If you try running it on Windows Server 8 in the future be sure to activate the Web Sockets feature.
If you are already using framework 4.5 but still no luck, add an HTTPS binding to your IIS website and access the website over HTTPS.

How to embed an asp.net site in a windows service (or vice versa)

I'm building a windows service but I would like to get some web pages to control some settings, get diagnostics, etc...
How would you go about combining an asp.net web site AND a windows service together ?
I know that WCF can be self hosted into an arbitrary process but can I do the same with asp.net ?
Another option would be to have my service logic in the asp.net web site application_start method to spawn long running threads. But then, I don't get window service built in feature such as auto start on boot up. Another issue might be that IIS might decide to recycle the process. Moreover, my service needs to open a raw tcp socket to accept connections. Can I do that in IIS ?
Thanks
I think the easiest and most robust way to do this is to have an ASP.NET Web Site running under IIS on the same server as the Windows Service. The Windows Service can host a WCF Web Service that will be accessible to the ASP.NET application.
I would have your Windows service self-host a WCF "configuration" service. The WCF service only needs to be exposed locally if the UI is on the same machine. If the windows service needs to open a separate raw socket for communications this can punch a hole through the firewall.
Then the ASP.NET UI can be hosted by IIS as usual, and call the WCF methods to perform the configuration tasks.
It seems like you really need both thingsā€”a web app hosted in IIS and a windows service hosted as windows service.
Then you can just share data between the two in some way, e.g. via a database.

Resources