devxlogo

GetWSException – Extracting the name of the SoapException’s inner exception

GetWSException – Extracting the name of the SoapException’s inner exception

' Extract the name of the SoapException's (the type of exception thrown by a ' web service) "inner" exception.'' Example:'   Try'       ' this call throws an exception'       Dim service As New localhost.SampleService()'       service.ThrowAnException()'   Catch ex As SoapException When ex.Code.Equals' (SoapException.VersionMismatchFaultCode)'   '   Catch ex As SoapException When ex.Code.Equals(SoapException.ServerFaultCode)'       lblMessage.Text = "SOAP Exception: " & ex.Message'   Catch ex As SoapException When GetWSException(ex) = ' "System.NullReferenceException"'       ' get details from the OuterXml property'       lblMessage.Text = ex.Detail.OuterXml'   End TryFunction GetWSException(ByVal ex As System.Web.Services.Protocols.SoapException) _    As String    ' parse the exception's Message property.    Dim mc As System.Text.RegularExpressions.MatchCollection = _        System.Text.RegularExpressions.Regex.Matches(ex.Message, _        "---> ([^:]+):")    If mc.Count >= 1 Then        ' we've found a match - the first ground contains the value.        Return mc.Item(0).Groups(1).Value    End IfEnd Function

devx-admin

Share the Post: