1

遇到肥皂异常问题。我在 asp.net Web 服务中抛出了肥皂异常,并且必须以某种方式让该异常(以 xml 的形式)显示在浏览器中,如下所示:

SOAP 1.1
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault><faultcode>soap:Client</faultcode>
<faultstring></faultstring>
<detail>
<Error>
<ErrorNumber>1</ErrorNumber>
<ErrorMessage>Error...</ErrorMessage>
</Error>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>

从 Web 服务抛出异常:

XmlDocument doc = new XmlDocument();
XmlNode detailNode = doc.CreateNode(XmlNodeType.Element, SoapException.DetailElementName.Name, SoapException.DetailElementName.Namespace);
XmlElement details = doc.CreateElement("Error");

XmlElement detailchild1 = doc.CreateElement("ErrorNumber");
detailchild1.InnerText = "1";
XmlElement detailchild2 = doc.CreateElement("ErrorMessage");
detailchild2.InnerText = "Error...";
details.AppendChild(detailchild1);
details.AppendChild(detailchild2);

detailNode.AppendChild(details);

throw new SoapException("Fault", SoapException.ClientFaultCode, "", details);

如果我使用调用该服务的 Windows 应用程序对其进行测试,我可以捕获异常并提取所有详细信息,因此似乎一切都适用于创建 xml 并引发异常。但我从浏览器得到的只是内部错误 500,这是根据我发现正常行为的其他答案。我可以通过更改 web.config、IIS 设置以某种方式在浏览器中获取该 xml 而不是内部错误 500...

4

1 回答 1

0

这不应该

throw new SoapException("Fault", SoapException.ClientFaultCode, "", details);

throw new SoapException("Fault", SoapException.ClientFaultCode, "", detailNode);

?

于 2013-02-25T10:47:51.503 回答