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. ProvideFault 和 HandleError 都传入一个 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 |
获取或设置操作者的值。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 和 FaultCode 对象的新 FaultReason 对象。Returns a new MessageFault object that uses the specified FaultCode and FaultReason objects. |
| CreateFault(FaultCode, FaultReason, Object) |
返回使用指定的 MessageFault、FaultCode 和详细信息对象的新 FaultReason 对象。Returns a new MessageFault object that uses the specified FaultCode, FaultReason, and detail object. |
| CreateFault(FaultCode, FaultReason, Object, XmlObjectSerializer) |
返回使用指定的 MessageFault、FaultCode、详细信息对象和 FaultReason 对象的新 XmlObjectSerializer 对象。Returns a new MessageFault object that uses the specified FaultCode, FaultReason, detail object, and XmlObjectSerializer objects. |
| CreateFault(FaultCode, FaultReason, Object, XmlObjectSerializer, String) |
返回使用指定的 MessageFault、FaultCode、详细信息对象、FaultReason 和操作者的新 XmlObjectSerializer 对象。Returns a new MessageFault object that uses the specified FaultCode, FaultReason, detail object, XmlObjectSerializer, and actor. |
| CreateFault(FaultCode, FaultReason, Object, XmlObjectSerializer, String, String) |
返回使用指定的 MessageFault、FaultCode、详细信息对象、FaultReason、操作者和节点值的新 XmlObjectSerializer 对象。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() |
获取当前实例的 Type。Gets 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) |
在写入详细内容之前调用。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. |