Is there an example check if the WCF service is online?

I will have a client application using a proxy for WCF service. This client will be a window form application making basicHttpBinding up to N number of endpoints at an address.

The problem I want to solve is that when any Windows application builds an application that goes through the Internet, so that my web server, which should have my web server on the Internet, needs to know that this particular WCF service is in network. I need an example of how this client in the background thread can only poll "WCF services .., Are You There?" Thus, our client application can notify clients before investing a lot of time in creating a working client side, in order to be disappointed that the WCF service is offline.

Again I am looking for an easy way to check the WCF service "Are You There?"

+4
source share
3 answers

What is this obsession to check if these services exist?

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

In fact, there is no use in constantly sending "are you there?" requests all over the wire ...

Even if you can have something like the Ping() method (which just returns a fixed value or something else - your service name or something else) - it only checks if your service is available - how about a database, which do you need for a request to receive data? What about the other services your service method depends on? It gets pretty messy and very difficult to figure out a way to check it all out - just see if there is any.

In short: no, there is no reliable and meaningful way to check whether this service is "there" and "live" - ​​just call! And be prepared to deal with failure - it will fail at times ....

+11
source

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

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

Do you see a problem with this snippet? What happens if the service is disconnected between checking the service’s health and the time it was called? This is a race condition and an error awaiting its appearance. So what you need to do, even if you can check the status of the service, is:

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

But in this block, the handleFailure () call is in two different places - we have two different ways to handle the same error condition - which seems bad. Thus, it can be safely reduced to:

 try { callService(); } catch(CommunicationException) { handleFailure(); } 
+5
source

If your service is hosted on IIS (or WAS) , you can implement the fault tolerance built into the IIS6 / 7 process model. If the worker does not work, the other will be launched in its place . How it works? Using Ping for analysis. It was called AppoPool Health Monitoring (described here ).

+2
source

Source: https://habr.com/ru/post/1310263/


All Articles