Link to home
Start Free TrialLog in
Avatar of InquisitiveMind
InquisitiveMind

asked on

Ping (IsAlive) between two WCF windows Services

Hi Experts,

I am looking to communicate between two Services (rather two instances of the same service) on two different servers. InstanceB should periodically check if InstanceA is alive.

These services are producing services and not consuming services. Both instances would be running at the same time, but only InstanceA would be producing the needed values. Only if InstanceA fails, would InstanceB takeover.

I'm thinking of taking the 'IsAlive' approach where InstanceB checks if InstanceA is alive every 10 seconds. I've added an IsAlive() method to my contract.  Since both the Instances would be Identical, how would my code to call the IsAlive() method or config file have to change?

I would appreciate a code sample.

Thanks in advance!
ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To just check availability/IsActive you can add a timmer in the both Services or only backup services. But it will be worth to ready following as it seems you are interested in failover/mirror services.

http://www.codeguru.com/csharp/.net/net_wcf/article.php/c19895/Introduction-to-Routing-Service-in-WCF-40.htm

and

http://stackoverflow.com/questions/3824881/design-pattern-for-wcf-client-switching-and-failover-capabilities

Thanks
Is it like client will call InstanceB....and instaneB will check if instanceA is alive then it will ask InstanceA to perform and work instaed of InstanceB doing the same work ?
Avatar of InquisitiveMind
InquisitiveMind

ASKER

@apeter:

InstanceA and InstanceB are both producing services(both auto start) and not consuming services (When I say producing services, they have a method called GenerateValues() which are generated every 15 seconds. )

Both of them are in a running state initially, but only InstanceA has the GenerateValues() method returning values to the client upon OnStart. InstanceB will not be returning the values. It should start generate values method only when a ping to InstanceA doesn't return a value. Is that any better?
then below might work ?
         if (InstanceAProxy.IsAlive())
                       InstanceAProxy.GenerateValues()
          else  if  (InstanceBProxy.IsAlive())
                       InstanceBProxy.GenerateValues()
          else
                  //what happens

But why InstanceA is not always live ?