MessageFault 類別

定義

表示 SOAP 錯誤在記憶體中的表示,此錯誤可傳遞給 CreateMessage 來建立包含錯誤的訊息。Represents an in-memory representation of a SOAP fault that can be passed to CreateMessage to create a message that contains a fault.

public ref class MessageFault abstract
public abstract class MessageFault
type MessageFault = class
Public MustInherit Class MessageFault
繼承
MessageFault

範例

下列程式碼範例會示範 MessageFault 最常見的使用方式。The following code example shows the most common use of MessageFault. ProvideFaultHandleError 都會傳入 MessageFault 物件,該物件可加以修改及傳回給系統 (如果是 ProvideFault),或是用來執行某些與自訂錯誤相關的行為 (如果是 HandleError)。Both the ProvideFault and HandleError pass in a MessageFault object that can be modified and returned to the system (in the case of ProvideFault) or used to perform some custom fault-related behavior (in the case of HandleError).

在此範例中, ProvideFault 方法會將所有 Exception 物件轉換成 MessageFault 包含型別物件的物件,並傳回 FaultException<TDetail> GreetingFault 自訂 MessageFault 至 WCF 的。In this example, the ProvideFault method converts all Exception objects into a MessageFault object that contains a FaultException<TDetail> object of type GreetingFault and returns that customized MessageFault to WCF.

#region IErrorHandler Members
public bool HandleError(Exception error)
{
  Console.WriteLine("HandleError called.");
  // Returning true indicates you performed your behavior.
  return true;
}

// This is a trivial implementation that converts Exception to FaultException<GreetingFault>.
public void ProvideFault(
  Exception error,
  MessageVersion ver,
  ref Message msg
)
{
  Console.WriteLine("ProvideFault called. Converting Exception to GreetingFault....");
  FaultException<GreetingFault> fe
    = new FaultException<GreetingFault>(new GreetingFault(error.Message));
  MessageFault fault = fe.CreateMessageFault();
  msg = Message.CreateMessage(
    ver,
    fault,
    "http://microsoft.wcf.documentation/ISampleService/SampleMethodGreetingFaultFault"
  );
}
#endregion
#Region "IErrorHandler Members"
Public Function HandleError(ByVal [error] As Exception) As Boolean Implements IErrorHandler.HandleError
  Console.WriteLine("HandleError called.")
  ' Returning true indicates you performed your behavior.
  Return True
End Function

' This is a trivial implementation that converts Exception to FaultException<GreetingFault>.
Public Sub ProvideFault(ByVal [error] As Exception, ByVal ver As MessageVersion, ByRef msg As Message) Implements IErrorHandler.ProvideFault
  Console.WriteLine("ProvideFault called. Converting Exception to GreetingFault....")
  Dim fe As New FaultException(Of GreetingFault)(New GreetingFault([error].Message))
  Dim fault As MessageFault = fe.CreateMessageFault()
  msg = Message.CreateMessage(ver, fault, "http://microsoft.wcf.documentation/ISampleService/SampleMethodGreetingFaultFault")
End Sub
#End Region

備註

每當您需要記憶體中的 SOAP 錯誤 (該錯誤可加以修改並用來建立包含錯誤資訊的 SOAP 訊息) 時,請使用 MessageFault 類別。Use the MessageFault class any time you need an in-memory SOAP fault that can be modified and used to create a SOAP message that contains the fault information.

一般來說,當您程式設計 MessageFault 介面時,會使用 IErrorHandler 類別。Typically, the MessageFault class is used when implementing the IErrorHandler interface. 在此情況下,Windows Communication Foundation (WCF) 會傳遞 MessageFault 物件,並將它用於您的特定需求 (例如,您可以自訂 MessageFault 或記錄錯誤資訊) 。In this case, Windows Communication Foundation (WCF) passes the MessageFault object and you use it for your specific needs (for example, you can customize the MessageFault or to log fault information). 但是,MessageFault 可用於需要自訂 SOAP 錯誤訊息處理的任何地方。However, MessageFault can be used anywhere custom SOAP fault message handling is required.

建構函式

MessageFault()

在衍生類別中呼叫時,初始化 MessageFault 類別的新執行個體。When called in a derived class, initializes a new instance of the MessageFault class.

屬性

Actor

取得或設定 Actor 的值。Gets or sets the value of the actor.

Code

取得 SOAP 錯誤碼。Gets the SOAP fault code.

HasDetail

取得值,此值指出 MessageFault 是否有詳細資料物件。Gets a value that indicates whether the MessageFault has a detail object.

IsMustUnderstandFault

取得或設定值,這個值指出此錯誤是否因為無法瞭解 SOAP 標頭所產生。Gets a value indicating whether this fault was caused by the failure to understand a SOAP header.

Node

取得 SOAP 節點,此節點包含訊息路徑上哪個 SOAP 節點造成錯誤的相關資訊。Gets the SOAP node containing information about which SOAP node on a message path cause the fault.

Reason

取得 SOAP 錯誤的文字描述。Gets a textual description of a SOAP fault.

方法

CreateFault(FaultCode, FaultReason)

傳回新的 MessageFault 物件,此物件會使用指定的 FaultCodeFaultReason 物件。Returns a new MessageFault object that uses the specified FaultCode and FaultReason objects.

CreateFault(FaultCode, FaultReason, Object)

傳回新的 MessageFault 物件,此物件會使用指定的 FaultCodeFaultReason 和詳細資料物件。Returns a new MessageFault object that uses the specified FaultCode, FaultReason, and detail object.

CreateFault(FaultCode, FaultReason, Object, XmlObjectSerializer)

傳回新的 MessageFault 物件,此物件會使用指定的 FaultCodeFaultReason、詳細資料物件和 XmlObjectSerializer 物件。Returns a new MessageFault object that uses the specified FaultCode, FaultReason, detail object, and XmlObjectSerializer objects.

CreateFault(FaultCode, FaultReason, Object, XmlObjectSerializer, String)

傳回新的 MessageFault 物件,此物件會使用指定的 FaultCodeFaultReason、詳細資料物件、XmlObjectSerializer 和 Actor。Returns a new MessageFault object that uses the specified FaultCode, FaultReason, detail object, XmlObjectSerializer, and actor.

CreateFault(FaultCode, FaultReason, Object, XmlObjectSerializer, String, String)

傳回新的 MessageFault 物件,此物件會使用指定的 FaultCodeFaultReason、詳細資料物件、XmlObjectSerializer、Actor 和節點值。Returns a new MessageFault object that uses the specified FaultCode, FaultReason, detail object, XmlObjectSerializer, actor, and node values.

CreateFault(FaultCode, String)

傳回新的 MessageFault 物件,此物件會使用指定的 FaultCode 和錯誤原因。Returns a new MessageFault object that uses the specified FaultCode and fault reason.

CreateFault(Message, Int32)

傳回新的 MessageFault 物件,此物件使用指定的 Message 及訊息緩衝區所指定的緩衝區大小上限。Returns a new MessageFault object that uses the specified Message and the specified maximum buffer size for the message buffer.

Equals(Object)

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

(繼承來源 Object)
GetDetail<T>()

傳回訊息錯誤的詳細資料物件。Returns the detail object of the message fault.

GetDetail<T>(XmlObjectSerializer)

傳回使用指定之 XmlObjectSerializer 的詳細資料物件。Returns the detail object that uses the specified XmlObjectSerializer.

GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetReaderAtDetailContents()

傳回 XmlDictionaryReader 物件,此物件置於 MessageFault 的詳細資料物件上。Returns an XmlDictionaryReader object that is positioned on the detail object of the MessageFault.

GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
MemberwiseClone()

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

(繼承來源 Object)
OnGetReaderAtDetailContents()

在衍生類別中呼叫時,會傳回 XmlDictionaryReader 物件,此物件置於 MessageFault 的詳細資料物件上。When called in a derived class, returns an XmlDictionaryReader object that is positioned on the detail object of the MessageFault.

OnWriteDetail(XmlDictionaryWriter, EnvelopeVersion)

在寫入詳細資料內容之前叫用 (Invoke)。Invoked prior to writing the detail contents.

OnWriteDetailContents(XmlDictionaryWriter)

在非抽象衍生類別中覆寫時,會寫入詳細資料項目的內容。When overridden in a non-abstract derived class, writes the contents of the detail element.

OnWriteStartDetail(XmlDictionaryWriter, EnvelopeVersion)

寫入使用指定之 XmlDictionaryWriter 和 SOAP 信封版本的開始項目。Writes the start element using the specified XmlDictionaryWriter and SOAP envelope version.

ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)
WasHeaderNotUnderstood(MessageHeaders, String, String)

取得值,這個值指出是否已瞭解 SOAP 訊息標頭。Gets a value indicating whether the SOAP message headers were understood.

WriteTo(XmlDictionaryWriter, EnvelopeVersion)

寫入使用指定之 XmlDictionaryWriter 和 SOAP 信封版本的訊息錯誤。Writes the message fault that uses the specified XmlDictionaryWriter and SOAP envelope version.

WriteTo(XmlWriter, EnvelopeVersion)

寫入使用指定之 XmlWriter 和 SOAP 信封版本的訊息錯誤。Writes the message fault that uses the specified XmlWriter and SOAP envelope version.

適用於