SoapException Class (System.Web.Services.Protocols)

Switch View :
ScriptFree
.NET Framework Class Library
SoapException Class

Represents the exception that is thrown when an XML Web service method is called over SOAP and an exception occurs.

Inheritance Hierarchy

System.Object
  System.Exception
    System.SystemException
      System.Web.Services.Protocols.SoapException
        System.Web.Services.Protocols.SoapHeaderException

Namespace:  System.Web.Services.Protocols
Assembly:  System.Web.Services (in System.Web.Services.dll)
Syntax

Visual Basic
<SerializableAttribute> _
Public Class SoapException _
	Inherits SystemException
C#
[SerializableAttribute]
public class SoapException : SystemException
Visual C++
[SerializableAttribute]
public ref class SoapException : public SystemException
F#
[<SerializableAttribute>]
type SoapException =  
    class
        inherit SystemException
    end

The SoapException type exposes the following members.

Constructors

  Name Description
Public method SoapException() Initializes a new instance of the SoapException class.
Protected method SoapException(SerializationInfo, StreamingContext) Initializes a new instance of the SoapException class with serialized data.
Public method SoapException(String, XmlQualifiedName) Initializes a new instance of the SoapException class with the specified exception message and exception code.
Public method SoapException(String, XmlQualifiedName, Exception) Initializes a new instance of the SoapException class with the specified exception message, exception code, and reference to the root cause of the exception.
Public method SoapException(String, XmlQualifiedName, String) Initializes a new instance of the SoapException class with the specified exception message, exception code, and URI that identifies the piece of code that caused the exception.
Public method SoapException(String, XmlQualifiedName, SoapFaultSubCode) Initializes a new instance of the SoapException class with the specified exception message, exception code, and subcode.
Public method SoapException(String, XmlQualifiedName, String, Exception) Initializes a new instance of the SoapException class with the specified exception message, exception code, URI that identifies the code that caused the exception, and reference to the root cause of the exception.
Public method SoapException(String, XmlQualifiedName, String, XmlNode) Initializes a new instance of the SoapException class with the specified exception message, exception code, URI that identifies the piece of code that caused the exception, and application specific exception information.
Public method SoapException(String, XmlQualifiedName, String, XmlNode, Exception) Initializes a new instance of the SoapException class with the specified exception message, exception code, URI that identifies the piece of code that caused the exception, application-specific exception information, and reference to the root cause of the exception.
Public method SoapException(String, XmlQualifiedName, String, String, XmlNode, SoapFaultSubCode, Exception) Initializes a new instance of the SoapException class with the specified exception message, exception code, URI that identifies the piece of code that caused the exception, application-specific exception information, and reference to the root cause of the exception.
Public method SoapException(String, XmlQualifiedName, String, String, String, XmlNode, SoapFaultSubCode, Exception) Initializes a new instance of the SoapException class with the specified exception message, exception code, URI that identifies the piece of code that caused the exception, URI that represents the XML Web service's function in processing the SOAP message, the human language associated with the exception, the application-specific exception information, the subcode for the SOAP fault and reference to the root cause of the exception.
Top
Properties

  Name Description
Public property Actor Gets the piece of code that caused the exception.
Public property Code Gets the type of SOAP fault code.
Public property Data Gets a collection of key/value pairs that provide additional user-defined information about the exception. (Inherited from Exception.)
Public property Detail Gets an XmlNode that represents the application-specific error information details.
Public property HelpLink Gets or sets a link to the help file associated with this exception. (Inherited from Exception.)
Protected property HResult Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception. (Inherited from Exception.)
Public property InnerException Gets the Exception instance that caused the current exception. (Inherited from Exception.)
Public property Lang Gets the human language associated with the exception.
Public property Message Gets a message that describes the current exception. (Inherited from Exception.)
Public property Node Gets a URI that represents the piece of code that caused the exception.
Public property Role Gets a URI that represents the XML Web service's function in processing the SOAP message.
Public property Source Gets or sets the name of the application or the object that causes the error. (Inherited from Exception.)
Public property StackTrace Gets a string representation of the immediate frames on the call stack. (Inherited from Exception.)
Public property SubCode Gets the optional error information contained in the subcode XML element of a SOAP fault.
Public property TargetSite Gets the method that throws the current exception. (Inherited from Exception.)
Top
Methods

  Name Description
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetBaseException When overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions. (Inherited from Exception.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetObjectData Sets the [T:System.Runtime.Serialization.][SerializationInfo] with information about the exception. (Overrides Exception.GetObjectData(SerializationInfo, StreamingContext).)
Public method GetType Gets the runtime type of the current instance. (Inherited from Exception.)
Public method Static member IsClientFaultCode Returns a value that indicates whether the SOAP fault code is equivalent to the Client SOAP fault code regardless of the version of the SOAP protocol used.
Public method Static member IsMustUnderstandFaultCode Returns a value that indicates whether the SOAP fault code is equivalent to MustUnderstand regardless of the version of the SOAP protocol used.
Public method Static member IsServerFaultCode Returns a value that indicates whether the SOAP fault code is equivalent to the Server SOAP fault code regardless of the version of the SOAP protocol used.
Public method Static member IsVersionMismatchFaultCode Returns a value that indicates whether the SOAP fault code is equivalent to the VersionMismatch SOAP fault code regardless of the version of the SOAP protocol used.
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Creates and returns a string representation of the current exception. (Inherited from Exception.)
Top
Events

  Name Description
Protected event SerializeObjectState Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception. (Inherited from Exception.)
Top
Fields

  Name Description
Public field Static member ClientFaultCode Specifies a SOAP fault code that represents a client call that is not formatted correctly or does not contain the appropriate information.
Public field Static member DetailElementName Gets an XmlQualifiedName that represents the Detail element of a SOAP Fault code.
Public field Static member MustUnderstandFaultCode A SOAP Fault Code that represents a SOAP element marked with the MustUnderstand attribute was not processed.
Public field Static member ServerFaultCode Specifies that a SOAP fault code that represents an error occurred during the processing of a client call on the server, where the problem is not due to the message contents.
Public field Static member VersionMismatchFaultCode A SOAP fault code that represents an invalid namespace for a SOAP envelope was found during the processing of the SOAP message.
Top
Remarks

The SoapException can either be thrown by the common language runtime or by an XML Web service method. The common language runtime can throw a SoapException if a response to a request is not formatted correctly. XML Web service methods can generate a SoapException by simply throwing an exception within the XML Web service method. If the client accessed the method over SOAP, the exception is caught on the server and wrapped inside a new SoapException. The SoapException thrown has the following property values:

Property

Value

Message

The Message property of the original exception.

Code

ServerFaultCode .

Actor

The URL of the XML Web service method.

Detail

null , but an empty detail element is present in the fault element.

An XML Web service method might throw a SoapException when clients call using SOAP. If an XML Web service throws the SoapException, other details can be added through the Actor, Code and Detail properties that cannot otherwise be set by an XML Web service method if another type of exception is thrown.

Examples

The following example throws a SoapException where the XML Web service method sets the Detail property.

Visual Basic

<%@ WebService Language="VB" class="ThrowSoapException"%>

Imports System
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml.Serialization
Imports System.Xml

Public Class ThrowSoapException
    Inherits WebService

    ' This XML Web service method generates a SOAP Client Fault code 
    <WebMethod()> _
    Public Sub myThrow()

        ' Build the detail element of the SOAP fault.
        Dim doc As New System.Xml.XmlDocument()
        Dim node As System.Xml.XmlNode = doc.CreateNode(XmlNodeType.Element, _
            SoapException.DetailElementName.Name, _
            SoapException.DetailElementName.Namespace)

        ' Build specific details for the SoapException.
        ' Add first child of detail XML element.
        Dim details As System.Xml.XmlNode = doc.CreateNode(XmlNodeType.Element, _
            "mySpecialInfo1", "http://tempuri.org/")

        ' Add second child of detail XML element with an attribute.
        Dim details2 As System.Xml.XmlNode = doc.CreateNode(XmlNodeType.Element, _
            "mySpecialInfo2", "http://tempuri.org/")
        Dim attr As XmlAttribute = doc.CreateAttribute("t", "attrName", _
            "http://tempuri.org/")
        attr.Value = "attrValue"
        details2.Attributes.Append(attr)

        ' Append the two child elements to the detail node.
        node.AppendChild(details)
        node.AppendChild(details2)

        'Throw the exception    
        Dim se As New SoapException("Fault occurred", SoapException.ClientFaultCode, _
                                    Context.Request.Url.AbsoluteUri, node)
        Throw se
        Return
    End Sub
End Class



C#

<%@ WebService Language="C#" class="ThrowSoapException"%>

using System;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Serialization;
using System.Xml;

public class ThrowSoapException : WebService 
{
//    This XML Web service method generates a SOAP Client Fault code 
    [WebMethod]
    public void myThrow(){

        // Build the detail element of the SOAP fault.
        System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
        System.Xml.XmlNode node = doc.CreateNode(XmlNodeType.Element, SoapException.DetailElementName.Name, SoapException.DetailElementName.Namespace);


        // Build specific details for the SoapException.
        // Add first child of detail XML element.
        System.Xml.XmlNode details = doc.CreateNode(XmlNodeType.Element, "mySpecialInfo1", "http://tempuri.org/");
        System.Xml.XmlNode detailsChild = doc.CreateNode(XmlNodeType.Element, "childOfSpecialInfo", "http://tempuri.org/");
        details.AppendChild(detailsChild);


        // Add second child of detail XML element with an attribute.
        System.Xml.XmlNode details2 = doc.CreateNode(XmlNodeType.Element, "mySpecialInfo2", "http://tempuri.org/");
        XmlAttribute attr = doc.CreateAttribute("t", "attrName", "http://tempuri.org/");
        attr.Value = "attrValue";
        details2.Attributes.Append(attr);

        // Append the two child elements to the detail node.
        node.AppendChild(details);
        node.AppendChild(details2);


        //Throw the exception.    
        SoapException se = new SoapException("Fault occurred", SoapException.ClientFaultCode,Context.Request.Url.AbsoluteUri,node);

        throw se;
        return;    }
}



Version Information

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also

Reference