سؤال

I have a C# program which will have multiple instances that need to communicate with each other, executing commands and sending data back and forth. Right now, this is accomplished using WM_COPYDATA, which is quite cumbersome. I would like to upgrade this to a WCF system using NetNamedPipeBindings. However, no matter what settings I try, I cannot get reentrant duplex communication working.

This would be a normal WCF call:

client calls proxy.foo
   server executes foo
   server finishes foo
client returns from proxy.foo

And this is what I want:

client calls proxy.foo
    server executes foo
    server calls callback.bar
        client executes bar
        client calls proxy.baz
            server executes baz
            server finishes baz
        client returns from proxy.baz
        client finishes bar
    server returns from callback.bar
    server finishes foo
client returns from proxy.foo

Critically, I want the client thread that calls proxy.foo to be the SAME THREAD that calls proxy.baz. For Windows Messages, this is par for the course. But no matter what settings I try, I just can't get this pattern working through WCF. Is it even possible?

هل كانت مفيدة؟

المحلول

Unless you make the calls async and manually handle the interleaving and (probably) marshaling to the right thread, I can not see how it is possible. After all, the client (thread) is calling the server and is blocked until the server returns with a response. So the call back to client will deadlock the code, as the client thread is already blocked.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top