tags:

views:

288

answers:

3

What is the most efficient way to check if WCF Service is available. (Pinging) It suppose to be binding configuration independent.

I prefer not to modify the Service Contracts with IsAlive() method. Ideally, I would expect that the WCF framework supports it. Otherwise, our solution is done by adding "ServiceAdministration" service, which is hosted in the same process as the above service. ServiceAdministration has a reference to the ServiceHost and it can check its State.

+3  A: 

The two things I do are a telnet check to make sure the WCF process has the socket open.

telnet host 8080

The second thing I do is always add an IsAlive method to my WCF contract so that there is a simple method to call to check that the service host is operating correctly.

public bool IsAlive() {
    return true;
}
sipwiz
+1 for IsAlive, which would always work irrespective of protocol (TCP, HTTP, etc.).We go further to implement Status(): this returns not only a bool for this service, but also a data structure representing the status of dependent services and databases.
Jeremy McGee
A: 

If its a 'published' WCF service, you should be able to request the WSDL schema, which is usually dynamically generated by the service. So if the WSDL schema returns a valid response, the service should be available. If its your service, you can guarantee this, a third party service might not publish a service description or it might be a non-dynamic WSDL.

So if your service was /service.svc, try a HTTP request to /service.svc?wsdl. If you get a valid 200 response, the service should be available.

Again, its not perfect when you don't control the service implementation.

-Jeff

Jeff
WCF doesn't always use HTTP, so that won't work across all binding configurations.
Dennis Palmer
In a production environment, it would be wise to hide the WSDL for security reasons. This is a good idea though for internal services, but not one where people outside the coorporate domain can get at it.
arabian tiger
+1  A: 

User sipwiz answer is absolutely the way I would do it - introduce a specific method you can call to get a response from your WCF service.

However, be aware of some limitations here: this will only prove that your client is able to call your service code. That might be good enough for you - perfect. But in my experience, the real trouble lies in the fact that other service methods will most likely call into yet other services and/or databases or what have you to actually perform their work. These systems might also be unreachable / unavailable, in which case your .IsAlive() will correctly report "all fine for this service", but when you go to actually call one of the "real" worker methods, that might very well still fail.

Basically, if you really want to know if all your service methods would be callable right now, you'd have to call each of them with some test data or find some other way to find out whether or not their backend systems are "alive". But such a .IsEverythingAlive() method could turn into quite a monster and take quite a long time to complete and still not be truly useful.... even if that method returns "all fine", a microsecond later when your real call comes in, one of the backend system might be dead.

So while the .IsAlive() gives you a quick and easy way to determine whether you can actually reach your own service, it's really not a guarantee that your real call will succeed - you just can't really check that.... you have to always assume that it'll fail and deal with the possibility of a failure and/or timeout.

Marc

marc_s