This has been discussed here but without a conclusion.
I would like to set up a WebSocket server in a self hosted Windows Service where I currently have multiple REST web services running on WCF. My requirements are not that advanced, I just need to consume an incoming stream of data. The problem is that I cannot change the way the data is send, if I could I would just convert it to a streamed HTTP POST, but this is not possible as the protocol is fixed.
According to Microsoft the WebSocket Class should be available from .NET Framework 4.5 and I am using .NET Framework 4.8 that is also supported but nowhere can I find how to self host it. There are many examples using IIS which I do not use.
So what I want to know is, 1) can the WebSocket class be used to self host a WebSocket Server inside a Windows Service? If so how is it done? Looking for some example code.
EDIT I think this might be somewhat undocumented but I finally got it to work. The magic seem to be replacing localhost or * with +. The following seem to work hosting the WebSocket while maintaining working WCF web services.
WebSocketsServer.Start("http://+:80/Socket/");
Some of it was described here but I could not make out when to use + or * and what their actual uses are.
When a port is specified, the host element can be replaced with "*" to indicate that the HttpListener accepts requests sent to the port if the requested URI does not match any other prefix. For example, to receive all requests sent to port 8080 when the requested URI is not handled by any HttpListener, the prefix is http://*:8080/. Similarly, to specify that the HttpListener accepts all requests sent to a port, replace the host element with the "+" character. For example, https://+:8080. The "*" and "+" characters can be present in prefixes that include paths.
I still do not think this makes sense fully. Anyone have a reference to why this would work?