开发者

How to call a WCF singleton service within a WCF singleton service without hanging?

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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜