tags:

views:

161

answers:

3

I will have a client application using a proxy to a WCF Service. This client will be a windows form application doing basicHttpBinding to N number of endpoints at an address.

The problem I want to resolve is that when any windows form application going across the internet to get my web server that must have my web server online will need to know that this particular WCF Service is online. I need an example of how this client on a background thread will be able to do a polling of just "WCF Service.., Are You There?" This way our client application can notify clients before they invest a lot of time in building up work client-side to only be frustrated with the WCF Service being offline.

Again I am looking for a simple way to check for WCF Service "Are You There?"

+7  A: 

What this obsession with checking whether those services are there??

Just call the service and as any defensive programming course will teach you, be prepared to handle exceptions.

There's really no benefit in constantly sending "are you there?" requests all over the wire...

Even if you could have something like a Ping() method (that just returns a fixed value or something - your service name or whatever) - that only checks whether your service is reachable - what about the database you need to query to get data from? What about other services your service method depends on? It gets quite messy and very very tricky to figure out a way to check all that - just to see if it's there.

In brief: no, there is no reliable and meaningful way to check whether a given service is "there" and "alive" - just call it ! And be prepared to handle a failure - it will fail at times....

marc_s
Yes there can be problems beyond the service layer.., agreed. I don't think your grasping the idea that it is important to give our clients an early signal that it is not there so that they will not work offline to end up with only getting frustrated. As far as the persistence goes we have methods that deal with that exception if we can at least reach the service layer. I need an answer to this problem with a solution and I don't not a set of additional potential problems resolve currently.
apolfj
Also just creating a ping method could work. I was wondering if the WCF plumbing had something built in for this action instead?
apolfj
@apolfj: no, the WCF runtime does not have anything to check the service availability, as far as I know. We have something like a Ping() method - called Version() - which returns the service version (from the assembly) - but our clients really never call that method...
marc_s
Even if you drop down to TCP, the only real way to ensure that a connection is alive is to write to it, and to receive a response. Anything else is *not* guaranteed to give you the actual connection status.
kyoryu
+4  A: 

There is no value in checking if a service is alive or not. Absolutely none. Why?

if(serviceIsAlive())
{
    callService();
}
else
{
    handleFailure()
}

Do you see the problem with this snippet? What happens if between the time you check if the service is alive, and the time you call it, the service goes down? This is a race condition, and a bug waiting to happen. So what you need to do, even if you can check the service condition, is:

if(serviceIsAlive())
{
    try
    {
        callService();
    }
    catch(CommunicationException)
    {
        handleFailure();
    }
}
else
{
    handleFailure();
}

But in this block, the handleFailure() call is in two different places - we've got two different paths to handle the same error condition - which seems like a bad thing. So this can be safely reduced to:

try
{
    callService();
}
catch(CommunicationException)
{
    handleFailure();
}
kyoryu
Agreed totaly. We fall in the same conclusion: the best way to verify if a service is up, is calling it and handling the exceptions that will occur. But also, we can setup an approach of "reliability", described in my post.
Erup
Well, keep in mind you can never really know if a service is 'up'. What you can know is if you've received a message from it recently. So, what you can really do in that case is send periodic heartbeat messages.
kyoryu
A: 

If your service is hosted in IIS (or WAS), you can perform a resiliency built-in to the IIS6/7 process model. If an worker process fails, another will be started in its place. How it works? Using Ping to analyse. Its called AppoPool Health Monitoring (described here).

Erup