Solved

Ping (IsAlive) between two WCF windows Services

Posted on 2013-01-02
5
1,496 Views
Last Modified: 2013-01-16
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!
0
Comment
Question by:InquisitiveMind
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 38739709
this post answers your question:
http://stackoverflow.com/questions/2867486/is-there-an-example-of-checking-on-if-a-wcf-service-is-online

basically, it says that you don;t need ping or IsAlive or anything special to detect if service is available.
simple use exception handling to catch timeout exception (or any combination of similar exceptions) and proceed according to your requirement (switch to the backup service).
0
 
LVL 16

Expert Comment

by:Imran Javed Zia
ID: 38739728
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
0
 
LVL 25

Expert Comment

by:apeter
ID: 38741904
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 ?
0
 

Author Comment

by:InquisitiveMind
ID: 38741931
@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?
0
 
LVL 25

Expert Comment

by:apeter
ID: 38742010
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 ?
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question