1

I'm starting up a little code project to learn from the process, but I am not sure what's the best way of communicating between the different parts.

  • First, I have a pure html/js client where the users need to get live updates frequently.
  • Secondly, I'm considering having a web api application running to provide data.
  • Thirdly I have a console application running, that needs to communicate with the web api application.

So I'm thinking about using WebSockets all the way from client->web api->console app, but I have trouble making it work. I can make the console app work as a server, but I can't figure out how to make the web api work as a client, so that when it spins up, creates a connection to the console app, and keeps it open for communication, while it delivers data to the clients upon requests.

I tried with different implementations and I have ended up with SignalR, as it seems like that's what people use today :)

Since I have all these problems getting a connection I am wondering if there are better ways of sending data that fulfills my requirements? If WebSocket (using SignalR) is the way to go, can you provide some links with working examples? I have tried all the top links from Google with no success ^^

Thanks in advance

Casper
  • 179
  • 1
  • 1
  • 11

1 Answers1

0

Your WebAPI project can act as WebSocket server as well. Check this link that uses an IHttpHandler, but you can also do it in a WebAIP's controller how is explained here : Using WebSockets with ASP.NET Web API

The console application should connect as client, using for example ClientWebSocket class.

WebSockets are persistent full duplex connections, so once the client is connected both ends can push information to the other end.

Community
  • 1
  • 1
vtortola
  • 34,709
  • 29
  • 161
  • 263
  • Thanks. I take a look at it tomorrow when I get home. I see that I have visitted those links before, but I will give it another try. Thanks for the input :) – Casper Sep 14 '15 at 21:29
  • I'll accept this answer as I was leading me in the right direction. None of the links actually provided the full story, but some of the elements were nice, like the IHttpHandler and to use the Web API app as the only server. What solved my problem is a very great tutorial on PluralSight called SignalR Introduction. He guides you through alt he necessary steps and I now got a working example :) – Casper Sep 16 '15 at 22:08
  • SignalR is good for small applications, but it has many limitations in terms of scalability ;) It is explained in their documenation about "Scaling Out". – vtortola Sep 16 '15 at 22:09