Reputation: 1022
My service is running currently on
localhost:17722/Book.svc
How can my client app know if the service running before trying to consume it?
Upvotes: 1
Views: 4353
Reputation: 4151
Setup a dummy method in the svc that returns a bool or something. Then hit it on a background thread at a specified interval. If the request times out you can then handle the timeout by displaying something that says the service is unreachable.
Upvotes: 1
Reputation: 31404
Don't check to see if a server is up before consuming it. Consume the service and handle any errors that occur during the call.
Even if you check that the service is up it can go down between the time you check that it is up and you call the service. So even if you check that it is up, you still need to handle it being down when you consume it.
The best way to check if a service is up is to try to use it.
Upvotes: 5
Reputation: 25783
I would apply the principal of Tell, don't ask in this situation. Just try to perform whatever operation you were intending on doing, and then handle the exception if it fails.
Why would your program be consuming a service if it was not necessary to the operation of the program?
Hey service, can I invoke your 'X' method? ... no? ... okay, I didn't want to anyway :P
Upvotes: 4
Reputation: 2551
Well this is not possible until you try the service (or ping the server). Calling your web service from your client application is like calling any other web service, how can you know that a "google's" web service is running before consuming it?
Once I had a similar problem and I just expose an operation that returns "something" (return true
for instance) that I called to know if the server application was "operational" and expecting a "timeout" or "500" error when not working.
Upvotes: 1
Reputation: 6735
Only some kind of ping
but without guarantee, that after you ping was ok the service will be not droped before your real request
To summarize:
Prepare you clint to handle dead service(s), faults etc
Upvotes: 5