Freigeben über


SoapException-Klasse

Stellt die bei Aufruf einer XML-Webdienstmethode über SOAP und bei Auftreten einer Ausnahme ausgelöste Ausnahme dar.

Namespace: System.Web.Services.Protocols
Assembly: System.Web.Services (in system.web.services.dll)

Syntax

'Declaration
<SerializableAttribute> _
Public Class SoapException
    Inherits SystemException
'Usage
Dim instance As SoapException
[SerializableAttribute] 
public class SoapException : SystemException
[SerializableAttribute] 
public ref class SoapException : public SystemException
/** @attribute SerializableAttribute() */ 
public class SoapException extends SystemException
SerializableAttribute 
public class SoapException extends SystemException

Hinweise

Die SoapException kann entweder durch die Common Language Runtime oder durch eine XML-Webdienstmethode ausgelöst werden. Die Common Language Runtime kann eine SoapException auslösen, wenn die Antwort auf eine Anforderung nicht korrekt formatiert ist. XML-Webdienstmethoden können eine SoapException generieren, indem sie einfach eine Ausnahme innerhalb der XML-Webdienstmethode auslösen. Wenn der Client über SOAP auf die Methode zugegriffen hat, wird die Ausnahme auf dem Server abgefangen und in eine neue SoapException eingebettet. Die ausgelöste SoapException verfügt über folgende Eigenschaftenwerte:

Eigenschaft

Wert

Message

Die Message-Eigenschaft der ursprünglichen Ausnahme.

Code

ServerFaultCode.

Actor

Der URL der XML-Webdienstmethode.

Detail

NULL (Nothing in Visual Basic), im Fehlerelement ist jedoch ein leeres Detailelement vorhanden.

Eine XML-Webdienstmethode kann möglicherweise eine SoapException auslösen, wenn Clientaufrufe über SOAP erfolgen. Wenn ein XML-Webdienst die SoapException auslöst, können weitere Details mithilfe der Eigenschaften Actor, Code und Detail hinzugefügt werden, die beim Auslösen eines anderen Ausnahmetyps nicht durch eine XML-Webdienstmethode festgelegt werden können.

Beispiel

Im folgenden Beispiel wird eine SoapException ausgelöst, wobei die XML-Webdienstmethode die Detail-Eigenschaft festlegt.

<%@ 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
<%@ 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;    }
}

Vererbungshierarchie

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

Threadsicherheit

Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

SoapException-Member
System.Web.Services.Protocols-Namespace