Solved

Ping (IsAlive) between two WCF windows Services

Posted on 2013-01-02
5
1,393 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
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now