SoapException SoapException SoapException SoapException Class

定义

表示通过 SOAP 调用 XML Web services 方法且出现异常时引发的异常。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可以由公共语言运行时或 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:

PropertyProperty Value
Message 原始异常的属性。 MessageThe Message property of the original exception.
Code ServerFaultCodeServerFaultCode.
Actor XML Web service 方法的 URL。The URL of the XML Web service method.
Detail null,但错误元素中存在一个空的详细信息元素。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通过添加其他详细信息,如果引发CodeDetail另一种类型的异常,则可以通过 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() SoapException() SoapException()

初始化 SoapException 类的新实例。Initializes a new instance of the SoapException class.

SoapException(SerializationInfo, StreamingContext) SoapException(SerializationInfo, StreamingContext) SoapException(SerializationInfo, StreamingContext) SoapException(SerializationInfo, StreamingContext)

用序列化数据初始化 SoapException 类的新实例。Initializes a new instance of the SoapException class with serialized data.

SoapException(String, XmlQualifiedName) SoapException(String, XmlQualifiedName) SoapException(String, XmlQualifiedName) 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(String, XmlQualifiedName, Exception) SoapException(String, XmlQualifiedName, Exception) 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(String, XmlQualifiedName, SoapFaultSubCode) SoapException(String, XmlQualifiedName, SoapFaultSubCode) 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) SoapException(String, XmlQualifiedName, String) SoapException(String, XmlQualifiedName, String) 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) SoapException(String, XmlQualifiedName, String, Exception) SoapException(String, XmlQualifiedName, String, 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) SoapException(String, XmlQualifiedName, String, String, String, XmlNode, SoapFaultSubCode, Exception) SoapException(String, XmlQualifiedName, String, String, String, XmlNode, SoapFaultSubCode, Exception) SoapException(String, XmlQualifiedName, String, String, String, XmlNode, SoapFaultSubCode, Exception)

使用以下内容初始化 SoapException 类的新实例:指定的异常消息、异常代码、标识引起异常的代码块的 URI、表示用于处理 SOAP 消息的 XML Web service 功能的 URI、与异常关联的人类语言、特定于应用程序的异常信息、SOAP 错误的子代码以及对异常的根源的引用。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) SoapException(String, XmlQualifiedName, String, String, XmlNode, SoapFaultSubCode, Exception) SoapException(String, XmlQualifiedName, String, String, XmlNode, SoapFaultSubCode, 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) SoapException(String, XmlQualifiedName, String, XmlNode) SoapException(String, XmlQualifiedName, String, XmlNode) 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) SoapException(String, XmlQualifiedName, String, XmlNode, Exception) SoapException(String, XmlQualifiedName, String, XmlNode, Exception) 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 ClientFaultCode ClientFaultCode 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 DetailElementName DetailElementName DetailElementName

获取 XmlQualifiedName,它表示 SOAP 错误代码的 Detail 元素。Gets an XmlQualifiedName that represents the Detail element of a SOAP Fault code.

MustUnderstandFaultCode MustUnderstandFaultCode MustUnderstandFaultCode MustUnderstandFaultCode

SOAP 错误代码,它表示没有处理用 MustUnderstand 特性标记的 SOAP 元素。A SOAP Fault Code that represents a SOAP element marked with the MustUnderstand attribute was not processed.

ServerFaultCode ServerFaultCode ServerFaultCode 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 VersionMismatchFaultCode VersionMismatchFaultCode 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 Actor Actor Actor

获取导致异常的代码段。Gets the piece of code that caused the exception.

Code Code Code Code

获取 SOAP 错误代码的类型。Gets the type of SOAP fault code.

Data Data Data Data

获取提供有关异常的其他用户定义信息的键/值对集合。Gets a collection of key/value pairs that provide additional user-defined information about the exception.

(Inherited from Exception)
Detail Detail Detail Detail

获取表示应用程序特定的详细错误信息的 XmlNodeGets an XmlNode that represents the application-specific error information details.

HelpLink HelpLink HelpLink HelpLink

获取或设置指向与此异常关联的帮助文件链接。Gets or sets a link to the help file associated with this exception.

(Inherited from Exception)
HResult HResult HResult HResult

获取或设置 HRESULT(一个分配给特定异常的编码数字值)。Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception.

(Inherited from Exception)
InnerException InnerException InnerException InnerException

获取导致当前异常的 Exception 实例。Gets the Exception instance that caused the current exception.

(Inherited from Exception)
Lang Lang Lang Lang

获取与该异常关联的人类语言。Gets the human language associated with the exception.

Message Message Message Message

获取描述当前异常的消息。Gets a message that describes the current exception.

(Inherited from Exception)
Node Node Node Node

获取表示导致异常的代码段的 URI。Gets a URI that represents the piece of code that caused the exception.

Role Role Role Role

获取一个 URI,它表示用于处理 SOAP 消息的 XML Web services 功能。Gets a URI that represents the XML Web service's function in processing the SOAP message.

Source Source Source Source

获取或设置导致错误的应用程序或对象的名称。Gets or sets the name of the application or the object that causes the error.

(Inherited from Exception)
StackTrace StackTrace StackTrace StackTrace

获取调用堆栈上的即时框架字符串表示形式。Gets a string representation of the immediate frames on the call stack.

(Inherited from Exception)
SubCode SubCode SubCode SubCode

获取 SOAP 错误中 subcode XML 元素包含的可选错误信息。Gets the optional error information contained in the subcode XML element of a SOAP fault.

TargetSite TargetSite TargetSite TargetSite

获取引发当前异常的方法。Gets the method that throws the current exception.

(Inherited from Exception)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetBaseException() GetBaseException() GetBaseException() GetBaseException()

当在派生类中重写时,返回 Exception,它是一个或多个并发的异常的根源。When overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions.

(Inherited from Exception)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext)

使用关于异常的信息设置 SerializationInfoSets the SerializationInfo with information about the exception.

GetType() GetType() GetType() GetType()

获取当前实例的运行时类型。Gets the runtime type of the current instance.

(Inherited from Exception)
IsClientFaultCode(XmlQualifiedName) IsClientFaultCode(XmlQualifiedName) IsClientFaultCode(XmlQualifiedName) 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) IsMustUnderstandFaultCode(XmlQualifiedName) IsMustUnderstandFaultCode(XmlQualifiedName) 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) IsServerFaultCode(XmlQualifiedName) IsServerFaultCode(XmlQualifiedName) 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) IsVersionMismatchFaultCode(XmlQualifiedName) IsVersionMismatchFaultCode(XmlQualifiedName) 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() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

创建并返回当前异常的字符串表示形式。Creates and returns a string representation of the current exception.

(Inherited from Exception)

事件

SerializeObjectState SerializeObjectState SerializeObjectState SerializeObjectState

当异常被序列化用来创建包含有关该异常的徐列出数据的异常状态对象时会出现该问题。Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception.

(Inherited from Exception)

适用于