【问题标题】:How to parse some WCF/RIA Services URL?如何解析一些 WCF/RIA 服务 URL?
【发布时间】:2012-01-24 12:27:51
【问题描述】:

假设我有一些表单,用户在其中输入了一些 WCF/RIA 服务 URL,他想保存它并确保该 URL 可以工作。

(主要条件是它可以是任何 WCF/RIA 服务 URL。)

如何正确解析以确保此 WCF/RIA 服务 URL 有效?

最佳策略是什么?

谢谢!

【问题讨论】:

  • “有效”是什么意思?执行 webhttprequest 并确保返回 200 OK 会不会太简单了?
  • @Paul Lemke。凉爽的!您能否提供您的方法的任何示例?
  • 下面是 Rajesh 的回答。

标签: .net wcf wcf-ria-services wcf-client


【解决方案1】:

使用以下代码获取状态响应以确保 URL 有效:

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.
            }

【讨论】:

    猜你喜欢
    • 2011-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-26
    • 1970-01-01
    • 1970-01-01
    • 2012-01-14
    • 2011-02-17
    相关资源
    最近更新 更多