The requirements look easy:
We need to monitor the health of the WCF services, availability of the WCF services. Are they up or down?
But we don’t want to call operations of the service because it sometime could change the service internal status and these changes are out of our control.
Some services have special Heartbeat() operation to make the health monitoring easily, but the most have not.
We don’t have to check the work status of the web-method. That means we don’t care if some underlying services, like SQL databases, don’t work and the services available but response with errors. We just want to know are web-services up or down, could they response at all or not. It should be something really easy.
Let’s start:
I thought this is quite routine task to the service consumers and there should be several routine decisions.
As I know the OpsMngr2007 use something simple to measure the web-service health.
I’ve asked gurus on the MSDN forums about this.
Dan Rigsby proposed:
“A one way Ping() method on the server works well. If there is an exception, then the channel is broken. You can have a timer run Ping against the server at some interval.
If this is a duplex callback system you need to be careful. The server might also need to check if the client is still alive. You cant have both the servicecontract and callbackcontract have the same named methods, so you will have to rename one of them.”
Thanks, Dan!

I’ve tried to

The ping works only for the host name, like
not for web-service URL

It is not what I want.

It checks the health of the host, not the web-service.
It does not cover cases with several services on the one host.
It does not cover cases when the host is OK but the service is not response.

Islam Eldemery proposed:
“try to subscribe to the events of the communication object (in the client side), so if a service stopped or disconnected you may handle the fault event.. (remember that it can only fault once).

proxy.InnerChannel.Faulted +=
new EventHandler(InnerChannel_Faulted);

proxy.InnerDuplexChannel.Faulted += new EventHandler(InnerDuplexChannel_Faulted);

see my example of handling a service in a chat application
if this is a duplex communication, to handle the service on the service side, try to check every time on each callback object you have, to see if someone has been aborted or not before you using it (may be a client disconnect for a network failure.. etc.)”

Islam, thanks for response!

Unfortunately with this technique we can intercept only errors after we unsuccessfully call the service operation, right?
It is not our case. We want to check the availability not “post mortem” but proactively. For instance, click a button and get health of all services. And we cannot call the service operations, it’s one of requirements.
Martin16 proposed:
Additional ideas (for IIS/HTTP WCF Services) are
1) a custom availability operation in your service which checks all resources and gives back a result your web application monitor can parse.
2) enable WCF performance counter and create a monitor on top of that.
3) buy Avicode MP (should provide native WCF Service support)”
Thanks for help, Martin16!

Yeah, 1) is the Heartbeat() operation. It doesn’t work in my case where the services are out of mu control.
For 2) First, we want actively to request the health status not to listen how the service responses to the requests of the other clients.
Second, the WCF performance counters… OK I use them with OpsMng2007 I don’t like them very-very much. (It’s another story).
3) The third-part utils should use the same APIs we use, not something secret. I also use OpsMngr2007. But I want to use simple and absolutely open (to me) source code.

So far so good.
Is it possible to use Mex endpoint or something like HttpRequest to <URL>?wsdl to make sure the service is up?

I’ve got one method from the book “Programming WCF Services” by Juval Lowy (page 71).
Code Snippet:

MetadataExchangeClient mexClient =

bool isServiceUp = true;
string address = “http://localhost/MyService.svc?wsdl”;new MetadataExchangeClient(new Uri(address),MetadataExchangeClientMode.HttpGet);
MetadataSet metadata = mexClient.GetMetadata();
// if service down I get the exception
catch (Exception ex)
isServiceUp =

I catch the Exception like {“Metadata contains a reference that cannot be resolved: “http://localhost/MyService.svc?wsdl”} System.Exception {System.InvalidOperationException}
Easy and don’t heavy load the service.
P.S. Please, make sure you’ve read good comment by Islam Eldemerybelow.