What exception or http status code when the server is off

I want to monitor the WCF server and send an email notification if the server is down. To do this, I am writing a console application to periodically send a dummy request to the server and check if a response has been sent. When the console application received an exception, the server encountered problems, including the server.

However, the problem is that I got a different exception in different server states. The following are exceptions returned from the server when it is on a different status. However, they all fall under the category of servers. Any idea ??:

When IIS is Disabled

System.ServiceModel.EndpointNotFoundException,

Message:
There was no listening to endpoints at http: //localhost/service.svc that could receive the message. This is often caused by the wrong address or SOAP action. See InnerException, if present, for more information. the details.

Internal exception message: remote server returned error: (404) Not found

When the Web.config file is intentionally changed to the wrong name:

System.ServiceModel.ServiceActivationException
Link: http: //localhost/service.svc
Message:
The requested service "http: //localhost/service.svc" cannot be activated. For more information, see Server Diagnostics Diagnostic Logs information.

For another unknown reason

System.ServiceModel.ServerTooBusyException
Message:
The HTTP service located at http: //localhost/service.svc is too busy.
Message:
The remote server responded with an error: (503) Server is unavailable.

Update 1

The exception is NOT always returning an http status code.

Update 2 In addition to using the WCF proxy to call the service, I must also use WebRequest, as shown below:

  try { WebRequest webRequest = WebRequest.Create(uri); webRequest.Method = "GET"; HttpWebResponse httpWebResponse = (HttpWebResponse)webRequest.GetResponse(); } catch () //what excpetion will tell me server is down?? { ... } 
+4
source share
2 answers

The actual content of the error should not be the last - if you do not control individual operations in the service (i.e. if POST with some data to a specific URL returns a specific answer) - realistic, then you just look at the status code; and for that you want to look at all the HTTP Status Codes and look at those that look like errors as far as you know.

As a good starting point, you can consider almost all 5xx codes; since they are all related to server errors.

You may also consider some of the 4xx codes (although they are usually associated with clients, so be ruthless). In particular:

400 - Bad Request - while you can be sure that the server must understand the request

404 - Not Found - if you are sure that this URL should be present

405 - Method Not Allowed - if you are sure that this HTTP verb should be supported (for example, POST or DELETE)

For some of the narrower 4xx codes, for example. 413 Request Entity Too Large or 414 Request-URI Too Long ; they could happen after several days or months of normal operation due to things like security updates. In this case, you do not necessarily determine that the service is disabled as such, but you can expect that it will not be able to fulfill the intended function.

+2
source

Any HTTP status result code in the 400 or 500 series is a problem that will prevent request processing. All these errors stem from System.ServiceModel.CommunicationException, so check this out.

+1
source

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


All Articles