How can I solve this WCF problem?

71 Views Asked by At

There is a WCF program(I will call this as "ABC"). This WCF program("ABC") can host a service or connect to the service that hosted other "ABC". So, "ABC" can be host program or client program. First "ABC" discover that any service that hosted, if find, connect to the service. or host the service.

If a "ABC" start, and then theother "ABC" start, "ABC" that start first will be host, and "ABC" that start after will be client.

In this point I have a question. If two "ABC" start in same time, The two "ABC" fail to find a hosted service all, and host respectively each. I want solve this. Although two "ABC" start simultaneously, the first should be host, and the second should be client. How can I this? Any other good algorithm ?

1

There are 1 best solutions below

1
On

One approach is to have a central location that tracks whether or not a host instance is running. Have each instance call it and say they want to be a host instance, and let it return a value indicating whether there is a host instance already running or not (or put another way, an indication of whether the caller should be a host instance). Have each instance enter the appropriate mode based on the reply. Let the server track the state and wait until the running host instance crashes, then you can watch the fireworks...