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.
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;
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With