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()

        // 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>();

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:

  1. 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.

  2. 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.

  1. 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?

  2. 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?

  3. 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).

  • 2
    SignalR would definitely be the "go-to" technology for this in .NET. I'd default to that until you find some reason that it's not a good fit. Commented Sep 14, 2015 at 8:31
  • Isn't SignalR strictly a web technology? This question doesn't mention if all or any of the clients are web based.
    – MetaFight
    Commented Sep 14, 2015 at 10:43
  • 1
    SignalR is a websocket type framework. For thicker clients,try ZeroMQ. To restrict clients base don licencing, simply reject any connections beyond a certain point - that would be an application-level feature, not part of the comms system.
    – gbjbaanb
    Commented Sep 14, 2015 at 10:51
  • 1
    To me, it seems you are having implementation problems. If you get errors (losing state) and you don't know why, that's a good sign that you don't understand the technology. Maybe you should make sure you know enough about WCF before you drop it.
    – nvoigt
    Commented Sep 15, 2015 at 7:06
  • @nvoigt valid point - i blew my mind and gave up at 2am, I actually resolved it the following day at 5pm (have answered on the link - WCF Host was starting up not my actual self hosted service!). Regardless this has opened my mind to some alternatives, SignalR may work depending on lifetime and recycling issues (although primarily thick clients I will likely target javascript inside browsers in future)... certainly abstracting out the communications channel to make it generic. netmq is very interesting also.
    – morleyc
    Commented Sep 15, 2015 at 9:24


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.