Over a million developers have joined DZone.

Extention method for validation web service address


Our projects consist of many web service and it’s so important that have usedapplication-to -application communications and these url address of web services must be valid.Because be valid or be running web service doesn’t  affect single app , affect all apps.

i am coded a extention method for validation web service address , in below code snippet you can see it

public static class WebServiceExtention
    public static bool isValidWebServiceUrl(this string url)
        bool rv = true;
        if (String.IsNullOrEmpty(url))
            rv = false;
        string Http_URL = HttpUtility.UrlDecode(url);
        HttpWebRequest ObjReq = (HttpWebRequest)HttpWebRequest.Create(Http_URL);
        ObjReq.Timeout = 36000;
        ObjReq.UseDefaultCredentials = true;
            if (ObjReq.GetResponse().ContentLength < 0)
                rv = false;
        catch (Exception)
            rv = false;
        return rv;

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}