I have an ASP.NET web application that calls a web service on a remote server. I want the application to be able to detect when it is not able to access the web service because of any sort of failure on the remote server.
It is essential that the application can differentiate between a failure on the remote server and a failure due to other circumstances. For example, it must be able to detect the difference between the web service url having been blocked by a firewall and the Http service on the remote server being unavailable.
Can anyone suggest a way of doing this, please? Ideally the solution will use the HttpStatusCode returned on the HttpWebResponse object.
Put a try clause around the code that calls the remote server and then catch a WebException. Inside the WebException object will be a HttpWebResponse with the status code and other tasty information about the response from the remote server.