I had written a WCF based "chat/notification" system but I am questioning my decision if WCF is a good fit.
I have an external 3rd party lib that calls my process when events arrive:
public class Service
{
ScreenPopService _service;
public void Start()
{
MyThirdPartyImports.RegisterUpdate(CallEvent);
// currently i am doing this with WCF, getting weirdness with singleton
// loosing member state on each call
_service = new ScreenPopService();
var host = new ServiceHost(service);
}
void CallEvent(uint pbxh, string info)
{
// do something and communicate this to the connected clients
// which currently is running in the WCF service. loosing state
// when i call in to _service here
// this loops through connected clients and calls them back via the
// OperationContext.Current.GetCallbackChannel<IScreenPopCallback>();
_service.WeNeedToNotifyClients(info);
}
}
This needs to hook in to the WCF service which in turn calls the clients. Clients log in and will be either authorized or not (depending on a max user limit setting on the server).
I am now seeing two issues with my decision to use WCF:
Some major weirdness involving scopes/lifetimes that I cant work out... basically my internal member state of the service including list of connected client callbacks (so i can call them back!) is being lost on each service call when I self-host. I can get around this by having a static reference inside the WcfService to an object in the hosting console app, but this smells to me.
If I call a client back via the callback channel it is not async and may hang the server, especially bad if I need to loop through a list of connected clients one at a time and call them back it could hang till timeout.
I am now reconsidering writing everything using TCP sockets and although I get closer to the coalface I loose the WCF coolness of sending messages across the network.
Does .NET allow an easy way for me to send objects across the wire as nicely as WCF does? If this were done on a TCP stream would I need to frame each "packet" so we know where the data for the object starts and ends?
Primarily I will be using thick clients (Windows apps) but may in future use javascript based clients. Any other frameworks (I have heard of SignalR will need to look in to this now) that people can recommend for messaging?
I have considered an event bus, but not sure how this would work given i want to have a limit on the number of clients that can connect at any time (for licensing).