How to check if a web service is up and running without using ping?

后端 未结 8 977
小蘑菇
小蘑菇 2020-12-30 09:42

How can i check if a method in a web service is working fine or not ? I cannot use ping. I still want to check any kind of method being invoked from the web service by the c

8条回答
  •  灰色年华
    2020-12-30 10:18

    just use try catch inside the method of your webservice and log exceptions to a log file or to the event log. Example:

    [OperationContract]
     public bool isGUID(string input)
    {
        bool functionReturnValue = false;
    
        try
        {
            Guid guid;
            functionReturnValue = Guid.TryParse(input, guid);
        }
        catch (Exception ex)
        {
            Log.WriteServerErrorLog(ex);
        }
    
        return functionReturnValue;
    }
    

    You don't need to ping the webservice, but instead ping the server with a watchdog service or something. There is no need to "ping" the webservice. I also think you don't need to do this anyway. Either your webservice works or it doesn't because of bad code.

提交回复
热议问题