我正在使用新的WebClient(url).UploadString(...来调用WCF WebInvoke Web方法。 该方法抛出了一个错误异常。
有没有办法获得除了以外的更详细的错误信息 “远程服务器返回错误:(400)错误请求”
我正在抛出一个错误(FaultException),其中包含所有相关信息。
此致 克雷格。
答案 0 :(得分:0)
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();
}