SoapException 類別

定義

表示例外狀況,在經由 SOAP 呼叫 XML Web Service 方法而發生例外狀況時擲回。Represents the exception that is thrown when an XML Web service method is called over SOAP and an exception occurs.

public ref class SoapException : SystemException
[System.Serializable]
public class SoapException : SystemException
type SoapException = class
    inherit SystemException
Public Class SoapException
Inherits SystemException
繼承
衍生
屬性

範例

下列範例SoapException會擲回,其中 XML Web Service 方法會Detail設定屬性。The following example throws a SoapException where the XML Web service method sets the Detail property.

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

備註

SoapException可以由 common language runtime 或 XML Web Service 方法擲回。The SoapException can either be thrown by the common language runtime or by an XML Web service method. SoapException如果要求的回應格式不正確,通用語言執行時間可能會擲回。The common language runtime can throw a SoapException if a response to a request is not formatted correctly. XML Web Service 方法只會在SoapException XML Web Service 方法中擲回例外狀況,藉此產生。XML Web service methods can generate a SoapException by simply throwing an exception within the XML Web service method. 如果用戶端透過 SOAP 存取方法,則會在伺服器上攔截例外狀況,並將其包裝SoapException在新的內。If the client accessed the method over SOAP, the exception is caught on the server and wrapped inside a new SoapException. SoapException擲回的具有下列屬性值:The SoapException thrown has the following property values:

屬性Property Value
Message 原始Message例外狀況的屬性。The Message property of the original exception.
Code ServerFaultCode.ServerFaultCode.
Actor XML Web Service 方法的 URL。The URL of the XML Web service method.
Detail null,但錯誤的詳細資料元素存在於 fault 元素中。null, but an empty detail element is present in the fault element.

SoapException當用戶端使用 SOAP 呼叫時,XML Web Service 方法可能會擲回。An XML Web service method might throw a SoapException when clients call using SOAP. 如果 XML Web Service SoapException擲回,則可以Actor透過來新增其他詳細資料, Code Detail如果擲回另一種類型的例外狀況,則會由 XML Web Service 方法無法以其他方式設定的屬性。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.

建構函式

SoapException()

初始化 SoapException 類別的新執行個體。Initializes a new instance of the SoapException class.

SoapException(SerializationInfo, StreamingContext)

使用序列化資料,初始化 SoapException 類別的新執行個體。Initializes a new instance of the SoapException class with serialized data.

SoapException(String, XmlQualifiedName)

初始化 SoapException 類別的新執行個體,含指定的例外狀況訊息和例外狀況碼。Initializes a new instance of the SoapException class with the specified exception message and exception code.

SoapException(String, XmlQualifiedName, Exception)

使用指定的例外狀況訊息、例外狀況代碼和例外狀況根本原因的參考,初始化 SoapException 類別的新執行個體。Initializes a new instance of the SoapException class with the specified exception message, exception code, and reference to the root cause of the exception.

SoapException(String, XmlQualifiedName, SoapFaultSubCode)

使用指定的例外狀況訊息、例外狀況代碼和子代碼,初始化 SoapException 類別的新執行個體。Initializes a new instance of the SoapException class with the specified exception message, exception code, and subcode.

SoapException(String, XmlQualifiedName, String)

使用指定的例外狀況訊息、例外狀況代碼和 URI (能識別造成例外狀況的程式碼片段),初始化 SoapException 類別的新執行個體。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.

SoapException(String, XmlQualifiedName, String, Exception)

使用指定的例外狀況訊息、例外狀況代碼、URI (能識別造成例外狀況的程式碼) 和例外狀況根本原因的參考,初始化 SoapException 類別的新執行個體。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.

SoapException(String, XmlQualifiedName, String, String, String, XmlNode, SoapFaultSubCode, Exception)

使用指定的例外狀況訊息、例外狀況代碼、識別造成例外狀況之程式碼片段的 URI、表示處理 SOAP 訊息之 XML Web 服務函式的 URI、與例外狀況關聯的人類語言、應用程式特定的例外狀況資訊、SOAP 錯誤的子代碼,以及例外狀況的根本原因參考,初始化 SoapException 類別的新執行個體。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.

SoapException(String, XmlQualifiedName, String, String, XmlNode, SoapFaultSubCode, Exception)

使用指定的例外狀況訊息、例外狀況代碼、URI (能識別造成例外狀況的程式碼片段)、應用程式特定的例外狀況資訊和例外狀況根本原因的參考,初始化 SoapException 類別的新執行個體。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.

SoapException(String, XmlQualifiedName, String, XmlNode)

使用指定的例外狀況訊息、例外狀況代碼、URI (能識別造成例外狀況的程式碼片段) 和應用程式特定的例外狀況資訊,初始化 SoapException 類別的新執行個體。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.

SoapException(String, XmlQualifiedName, String, XmlNode, Exception)

使用指定的例外狀況訊息、例外狀況代碼、URI (能識別造成例外狀況的程式碼片段)、應用程式特定的例外狀況資訊和例外狀況根本原因的參考,初始化 SoapException 類別的新執行個體。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.

欄位

ClientFaultCode

指定 SOAP 錯誤碼,表示未正確格式化或未包含適當資訊的用戶端呼叫。Specifies a SOAP fault code that represents a client call that is not formatted correctly or does not contain the appropriate information.

DetailElementName

取得 XmlQualifiedName,表示 SOAP 錯誤碼的 Detail 項目。Gets an XmlQualifiedName that represents the Detail element of a SOAP Fault code.

MustUnderstandFaultCode

SOAP 錯誤碼 (表示標記有 MustUnderstand 屬性的 SOAP 項目) 未經處理。A SOAP Fault Code that represents a SOAP element marked with the MustUnderstand attribute was not processed.

ServerFaultCode

指定表示在伺服器上處理用戶端呼叫期間發生之錯誤的 SOAP 錯誤碼,其中問題不在於訊息內容。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.

VersionMismatchFaultCode

SOAP 錯誤碼,表示在 SOAP 訊息處理期間,找到 SOAP 信封的無效命名空間。A SOAP fault code that represents an invalid namespace for a SOAP envelope was found during the processing of the SOAP message.

屬性

Actor

取得造成例外狀況的程式碼部分。Gets the piece of code that caused the exception.

Code

取得 SOAP 錯誤碼的類型。Gets the type of SOAP fault code.

Data

取得提供例外狀況之其他使用者定義相關資訊的索引鍵/值組集合。Gets a collection of key/value pairs that provide additional user-defined information about the exception.

(繼承來源 Exception)
Detail

取得 XmlNode,表示應用程式特定的錯誤資訊明細。Gets an XmlNode that represents the application-specific error information details.

HelpLink

取得或設定與這個例外狀況相關聯的說明檔連結。Gets or sets a link to the help file associated with this exception.

(繼承來源 Exception)
HResult

取得或設定 HRESULT,它是指派給特定例外狀況的編碼數值。Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception.

(繼承來源 Exception)
InnerException

取得造成目前例外狀況的 Exception 執行個體。Gets the Exception instance that caused the current exception.

(繼承來源 Exception)
Lang

取得與這個例外狀況相關聯的人類語言。Gets the human language associated with the exception.

Message

取得描述目前例外狀況的訊息。Gets a message that describes the current exception.

(繼承來源 Exception)
Node

取得 URI,表示造成例外狀況的程式碼片段。Gets a URI that represents the piece of code that caused the exception.

Role

取得 URI,表示處理 SOAP 訊息的 XML Web Service 的功能。Gets a URI that represents the XML Web service's function in processing the SOAP message.

Source

取得或設定造成錯誤的應用程式或物件的名稱。Gets or sets the name of the application or the object that causes the error.

(繼承來源 Exception)
StackTrace

取得呼叫堆疊上即時運算框架的字串表示。Gets a string representation of the immediate frames on the call stack.

(繼承來源 Exception)
SubCode

取得 SOAP 錯誤之 subcode XML 項目中包含的選擇性錯誤資訊。Gets the optional error information contained in the subcode XML element of a SOAP fault.

TargetSite

取得擲回目前例外狀況的方法。Gets the method that throws the current exception.

(繼承來源 Exception)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetBaseException()

在衍生類別中覆寫時,傳回一或多個後續的例外狀況的根本原因 ExceptionWhen overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions.

(繼承來源 Exception)
GetHashCode()

作為預設雜湊函數。Serves as the default hash function.

(繼承來源 Object)
GetObjectData(SerializationInfo, StreamingContext)

使用例外狀況的相關資訊來設定 SerializationInfoSets the SerializationInfo with information about the exception.

GetType()

取得目前執行個體的執行階段類型。Gets the runtime type of the current instance.

(繼承來源 Exception)
IsClientFaultCode(XmlQualifiedName)

傳回值,指出 SOAP 錯誤碼是否相當於 Client SOAP 錯誤碼,而不論所使用的 SOAP 通訊協定版本。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.

IsMustUnderstandFaultCode(XmlQualifiedName)

傳回值,指出 SOAP 錯誤碼是否相當於 MustUnderstand,而不論所使用的 SOAP 通訊協定版本。Returns a value that indicates whether the SOAP fault code is equivalent to MustUnderstand regardless of the version of the SOAP protocol used.

IsServerFaultCode(XmlQualifiedName)

傳回值,指出 SOAP 錯誤碼是否相當於 Server SOAP 錯誤碼,而不論所使用的 SOAP 通訊協定版本。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.

IsVersionMismatchFaultCode(XmlQualifiedName)

傳回值,指出 SOAP 錯誤碼是否相當於 VersionMismatch SOAP 錯誤碼,而不論所使用的 SOAP 通訊協定版本。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.

MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

建立並傳回目前例外狀況的字串表示。Creates and returns a string representation of the current exception.

(繼承來源 Exception)

事件

SerializeObjectState

當例外狀況序列化,以建立包含例外狀況相關序列化資料的例外狀況狀態物件時,就會發生此事件。Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception.

(繼承來源 Exception)

適用於