Welcome   |   ASP.NET   |   Web Services   |   Class Browser   
  |   I want my samples in...      

ASP.NET Web Services QuickStart Tutorial

ASP.NET Web Service That Throws a Soap Exception with Custom Information

The server can send custom fault information to the client using a SoapException. When a SoapException is thrown (and not caught) the server sends the error information on the wire in the form of a SOAP fault. The SOAP fault is deserialized back into a SoapException at the client. Custom (machine-readable) error information is sent in the Detail element of a SOAP fault. A SOAP fault also includes a human-readable error message, a fault code and optionally a SOAP actor.

		
'assume that there was an error validating the SOAP Message
If True Then
    Dim doc As New XmlDocument()
    'insert your own XML into the XmlDocument, 
    'this will go into the Detail element of the SOAP fault
    Dim errorMsg As String = "An error was received..."
    'the SOAP fault will contain a human-readable error message, 
    'the fault code, the SOAP actor, and the detail element  
    Dim exc As New SoapException(errorMsg, SoapException.ClientFaultCode, "", detail)
    Throw exc
End If
VB

Run VB Sample
Run Sample View Source



Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2005 Microsoft Corporation. All rights reserved.