I have two services, one that calls another. Both are marked as singletons as follows:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,
ConcurrencyMode = ConcurrencyMode.Multiple)]
public class Service : IService
And I set these up with a ServiceHost as follows:
ServiceHost serviceHost = new ServiceHost(singletonElement);
serviceHost.Open();
When the parent service tries to call the child service on the same machine, the parent service hangs, waiting for the child service.
I'm already considering moving away from the singleton model, but is there anything wrong with my approach? Is there an explanation for this behavior and a way out of it?
The problem was that I was hosting within a WPF application and did not set UseSynchronizationContext to false. This makes the WCF service host in the UI thread, thus causing a deadlock when you have one service (on the UI thread) calling another service (also on a UI thread).