多个客户端的WCF阻塞问题! [英] WCF Blocking problem with mutiple clients!

查看:332
本文介绍了多个客户端的WCF阻塞问题!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎对WCF有阻止的问题.

I seem to have a blocking issue with WCF.

说我有两个用户,每个用户都使用net.tcp创建了自己的类实例,该实例在WCF主机上公开,其端点类似于"net.tcp://localhost:32000/SymHost/".该类是PerSession上下文,并发是可重入的.该类公开了两个方法Alive(),它们立即返回一个布尔值true;另一个是我插入的AliveWait方法,它执行Thread.Sleep 4秒钟,然后返回true(测试目的).

Say I have two users and each have created their own instance of a class exposed on a WCF host using net.tcp with endpoint something like this "net.tcp://localhost:32000/SymHost/". The class is PerSession context and concurrency is reentrant. The class exposes two methods Alive() which return a bool of true straight away and an AliveWait which I inserted which does a Thread.Sleep for 4 seconds before returning true (testing purposes).

现在客户端1调用AliveWait(),在此期间他被阻塞,这很公平,但是如果客户端2在其自己的实例上对Alive()进行调用,则他必须等到客户端1的调用返回-此行为是不是我所期望的吗?我希望客户端2继续进行下去,好像什么都没发生一样,或者这与它们都共享同一端点的事实有关?

Now client 1 calls AliveWait() during which time he is blocked which is fair enough but then if client 2 makes a call to Alive() on its own instance he has to wait until client 1's call is returned - this behaviour is not what I would have expected? I would have expected client 2 to carry on as if nothing has happened or is this to do with the fact that they both share the same endpoint?

任何人都可以解释发生了什么事,以及如何确保客户端2可以不间断地调用其自己的实例吗?

Can anyone explain what is going on and how I can make sure that client 2 can call its own instance uninterrupted?

任何帮助,不胜感激!

推荐答案

我发现它是什么!我忘记了在Test类的ServiceBehaviour中将UseSynchronizationContext设置为false.默认情况下为true,它将同步服务上的所有调用以在同一线程上运行!因此,来自其他客户端的任何后续呼叫都只需排队!

I found out what it was! I had forgotten to put the UseSynchronizationContext to false in the ServiceBehaviour of the Test class. This defaults to true which synchronises all calls on the service to run on the same thread! So any subsequent calls from other clients were simply queued!

这篇关于多个客户端的WCF阻塞问题!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆