views:

185

answers:

2

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?

+1  A: 

The parent service hangs it because might be becoz the child service method is taking too long. If it takes long time to return call it asyncronously or make child servcie method IsOneWayo=True in the OpearationContract arrtribute.

One way service is Fire & Forget kind of call it does not return any value.

Ajax2020
A: 

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

Michael Hedgpeth