当 WCF 服务调用返回错误时,如何捕获/访问soapenv:Detail 节点中的信息?
单独捕获 FaultException 并不包括它,因为我可以在服务跟踪日志中看到数据。
解决方案/解决方法:
Catch ex As FaultException
Dim detailsMsg As String = String.Empty
Dim mf As MessageFault = ex.CreateMessageFault
If mf.HasDetail Then
Dim ns As XNamespace = "http://url"
Dim detailedMessage As XElement = mf.GetDetail(Of XElement)()
Dim messageElement As XElement = detailedMessage.Descendants(ns + "Message").SingleOrDefault
If messageElement IsNot Nothing Then
detailsMsg = messageElement.Value
End If
End If
End Try
仍然无法赶上:
Catch ex As FaultException(Of XElement)
这会很好...