IanL
IanL

Reputation: 626

How to check if a web service is available using .NET

If a .NET application needs to call a web service is there a good solution for checking if the web service is currently up and available, outside of calling a specific web method?

On my web services I usually include some sort of status method for testing, but this becomes an issue when using a third party web service.

Upvotes: 3

Views: 18773

Answers (3)

Allen Rice
Allen Rice

Reputation: 19446

You would need to call a method regardless, otherwise you wouldn't know if the web service itself was running. I.e. The server could be running but the web service stopped.

We do this for some of our web services and it exposes neat functionality. We can have it return true/false and a failed call or false means its down. This lets you "return true;" always or conditionally return false if you choose to, such as blocking specific clients or turning the service off without actually stopping the web service, etc.

Upvotes: 0

James
James

Reputation: 12806

Another solution is just to do a simple HTTP get on the URL of the service. And look at the response code (i.e. 404 etc). The cool thing about this is that you don't have to post any data or call any methods.

Upvotes: 2

Randolpho
Randolpho

Reputation: 56448

Nope.

One thing you might do is create a ServiceIsUp method that does nothing, only returning true. If your server was hung for whatever reason, your request would timeout.

Upvotes: 0

Related Questions