Home   |   QuickStart Welcome   |   ASP.NET   |   Web Services   |   How Do I...?   
  |   I want my samples in...      

ASP.NET 2.0 Web Services QuickStart Tutorial

ASP.NET Web Service That Throws a Soap Extension 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)
{
    XmlDocument doc = new XmlDocument();
    //insert your own XML into the XmlDocument, 
    //this will go into the Detail element of the SOAP fault
    string errorMsg = "An error was received...";
    //the SOAP fault will contain a human-readable error message, 
    //the fault code, the SOAP actor, and the detail element    
    SoapException exc = new SoapException(errorMsg, SoapException.ClientFaultCode, "", detail);
    throw exc; 
}
C#

Run VB Sample
Run Sample View Source



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