简体   繁体   中英

How to check if a WCF service is operational?

Is there a quick and reliable way to check if a WCF service is available and accepting requests, perhaps some best practice built in method? Obviously from code.

Thanks

You can to implement an empty method and call it every time you want.

You could to try this article too: How to: Use Health Monitoring to Instrument a WCF Service for Security

As Rubens already mentioned, you could create a dummy "ping" method on your service to check. This works OK and might be enough for you - BUT : such a ping method of course can only guarantee that your service is reachable and responsive.

In many cases, your service method will in turn depend on other resources - eg you need to read data from a database, parse an XML file, call out to yet another service etc. So even if your service is available and responsive on your Ping method doesn't at all guarantee that another call on your service will succeed.

A simple Ping method on your service typically cannot check the availability of all those dependant systems / resources. So in the end, it's really only half (or less) of the story you can check - just be aware of that!

To make a long story short: you can't really check for a service being available and up and running - you basically just need to call it when you need it, and be prepared to handle bad things, like timeouts, network link broken etc. Good defensive programming practices apply even more so in the connected, service-oriented world!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM