【问题标题】:get fault information from a webinvoke method using WebClient使用 WebClient 从 webinvoke 方法获取故障信息
【发布时间】:2011-11-08 23:50:18
【问题描述】:

我正在使用 new WebClient(url).UploadString(... 来调用 WCF WebInvoke Web 方法。 该方法正在引发错误异常。

有没有什么方法可以获取更详细的错误信息 "远程服务器返回错误:(400) Bad Request"

我抛出了一个包含所有相关信息的错误 (FaultException)。

问候 克雷格。

【问题讨论】:

    标签: wcf rest exception-handling


    【解决方案1】:
    try {
        string result = client.UploadString(
                "http://localhost:8080/method",
                "POST",
                xml.ToString()
        );
        result.Dump();
    } catch (WebException ex) {
        XNamespace exn = "http://www.w3.org/1999/xhtml";        
        var error = from node in XElement.Load(ex.Response.GetResponseStream()).Descendants(exn + "p")
                    select node.Value;
        error.Dump();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多