我在捕捉SOAP FaultException
时遇到问题。
服务器响应是:
<soap-env:Fault xmlns:soap-env = "http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<faultcode>soap-env:Client</faultcode>
<faultstring>Test</faultstring>
<detail>
<brin:FaultResponse>
<cdm:SingleError>
<cdm:ErrorCode>-1</cdm:ErrorCode>
<cdm:ErrorDetails>Custom detail</cdm:ErrorDetails>
</cdm:SingleError>
</brin:FaultResponse>
</detail>
</soap-env:Fault>
在.NET代码中,我有以下try catch块:
try
{
//call client
}
catch(FaultException faultException)
{
}
catch (Exception ex)
{
//Always get here - with type of Exception == CommunicationException
}
答案 0 :(得分:0)
您可能需要:
catch (FaultException faultex) {
var msgFault = faultex.CreateMessageFault();
if (msgFault.HasDetail) {
var detailNode = msgFault.GetDetail<XmlElement>();
//detailNode is where you will find what you were looking for
}
}