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

后端 未结 8 924
小蘑菇
小蘑菇 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:00

    You can write your self a little tool or windows service or whatever you need then look at these 2 articles:

    C#: How to programmatically check a web service is up and running?

    check to if web-service is up and running - efficiently

    EDIT: This was my implementation in a similar scenario where I need to know if an external service still exists every time before the call is made:

    bool IsExternalServiceRunning
        {
            get
            {
                bool isRunning = false;
                try
                {
                    var endpoint = new ServiceClient();
                    var serviceUri  = endpoint.Endpoint.Address.Uri;
                    var request = (HttpWebRequest)WebRequest.Create(serviceUri);
                    request.Timeout = 1000000;
                    var response = (HttpWebResponse)request.GetResponse();
                    if (response.StatusCode == HttpStatusCode.OK)
                        isRunning = true;
                }
                #region
                catch (Exception ex)
                {
                    // Handle error
                }
                #endregion
                return isRunning;
            }
        }
    

提交回复
热议问题