Search code examples
.netwcfwcf-ria-serviceswcf-client

How to parse some WCF/RIA Services URL?


Let's say I have some form where user input some WCF/RIA Services URL and he wants to save it and be sure that URL will work.

(The main condition is that it could be any WCF/RIA Services URL.)

How to parse it correctly to make sure that this WCF/RIA Services URL is valid?

Which the best strategy is?

Thanks!


Solution

  • Use the code below to get back a status response to make sure that the URL is valid:

    var request = WebRequest.Create(serviceUrl) as HttpWebRequest;
                if (request != null)
                {
                    request.ContentType = "application/xml";
                    request.Method = "GET";
                }
    var response = request.GetResponse() as HttpWebResponse;
                if(response.StatusCode == HttpStatusCode.OK)
                {
                     //valid url, continue to persist.
                }
                else
                {
                     //invalid url throw your exception or show message.
                }