2

How do you catch/access the info within the soapenv:Detail node when a WCF service call returns an error??

Catching the FaultException alone does not include it bu I can see the data in the service trace log.

Solution/Workaround:

        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

Still can't catch with:

Catch ex As FaultException(Of XElement)

Which would have been nice...

baileyswalk
  • 1,198
  • 2
  • 17
  • 29

1 Answers1

1

You can catch it, but you have to specify the type used for the detail instead of XElement.

Catch ex As FaultException(Of MyFaultDetails) 

The type for this detail should have been automatically generated by visual studio if you use "add web reference" and this is a WCF service.

You can then use:

ex.Detail

to access the details via properties.

Edit: Make sure that your web service methods are decorated with the FaultContract attribute:

<FaultContract(GetType(MyFaultDetails))>_ 
aKzenT
  • 7,775
  • 2
  • 36
  • 65
  • This is what I first tried but it would not catch, I can see the xml representation of the object in the reply but cannot use the wsdl generated object to catch the details. Does the namespace have any impact on this? It is different to the rest of the document. – baileyswalk Apr 04 '12 at 15:41
  • did you put the FaultContract attribute in the web service methods? (check my edit) – aKzenT Apr 04 '12 at 21:28
  • The service is external I'm only referencing it, can I check this client side? – baileyswalk Apr 13 '12 at 11:16
  • I think you should be able to see the attribute client side, looking at the generated code for the web service (Reference.vb), but it's difficult to change, because it's an auto generated files and your changes can be overwritten at any time. Maybe you should contact the author of the web service... – aKzenT Apr 15 '12 at 16:14