How to know if a Web Service is Available

0

Good afternoon, I would like to be able to verify if a web service is available, as well as it would be a ping to a url, I have this method, but it falls when putting the url of some web service.

        Ping pings = new Ping();
        int timeout = 10;

        if (pings.Send("http://www.sunat.gob.pe", timeout).Status == IPStatus.Success)
        {
            MessageBox.Show("Exito");

        }
        else
        {
            MessageBox.Show("Error");
        }
    
asked by Josue Puma Apaza 09.01.2017 в 21:06
source

1 answer

1

try the following:

        var url = "http://www.w3schools.com/xml/tempconvert.asmx";

        try
        {
            var myRequest = (HttpWebRequest)WebRequest.Create(url);

            var response = (HttpWebResponse)myRequest.GetResponse();

            if (response.StatusCode == HttpStatusCode.OK)
            {
                Debug.Write(string.Format("{0} Disponible", url));
            }
            else
            {
                Debug.Write(string.Format("{0} Status: {1}", url, response.StatusDescription));
            }
        }
        catch (Exception ex)
        {
            Debug.Write(string.Format("{0} No Disponible: {1}", url, ex.Message));
        }
    
answered by 10.01.2017 в 13:59