开发者

Running a WCF Service host and WCF client proxy on the same Windows form

we're trying to build a "web" of connected clients, where each client.exe also provides the service host that remote clients connect to.

The idea is that whenever a remote client connects to the local client, a form is used to visually show the connected remote clients. Whenever a new remote client connects or disconnects, the form is updated from the service isntance.

However, the local client is also accessing the same form for various reasons (provide the user ways to interact with the remote clients).

My question is: when would I run into problems with synchronization and thread problems when both the client proxy and the service host access the form? The service is configured with ConcurrencyMode.Single and Session.Required. The client is a singleton. I am already using locks to synchronize access to members, callbacks from the service also are thread safe. Still, can there be deadlocks?开发者_JAVA技巧 The load is minimal: at most 2 clients would send data at once, and the total number of clients would not exceed 25. Basically, the application would be used so that ONE (1) client can talk to ONE other client.

NB: I undertand there is also the possibility of running only one WCF service on a dedicated machine that all clients can connect to. I am still asking about this particular scenario, where each client also provides a service host. Thanks.


Haven't you answered your own question?

Of course you'll have synchronization problems. Some of these will be solved by the fact that WinForms controls can only be accessed from the thread that created them. You'll have to do all of your UI work on that thread by calling the Control.Invoke or Control.BeginInvoke methods.

On the other hand, there's no inherent problem with hosting a WCF service in the same process as WCF proxies. In fact, I was recently able to write a unit test that used a proxy class to access a mock service that was hosted in the unit test.


As soon as you have multiple threads and locks, you can have deadlocks, but they are bugs, not inherent problems in the design.

In the specific case, remember to use Invoke to access the form as you can do it only in the thread that created it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜