MessageFault MessageFault MessageFault MessageFault Class

Definition

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
Inheritance
MessageFaultMessageFaultMessageFaultMessageFault

Examples

The following code example shows the most common use of MessageFault. 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).

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

Remarks

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.

Typically, the MessageFault class is used when implementing the IErrorHandler interface. 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). However, MessageFault can be used anywhere custom SOAP fault message handling is required.

Constructors

MessageFault() MessageFault() MessageFault() MessageFault()

When called in a derived class, initializes a new instance of the MessageFault class.

Properties

Actor Actor Actor Actor

Gets or sets the value of the actor.

Code Code Code Code

Gets the SOAP fault code.

HasDetail HasDetail HasDetail HasDetail

Gets a value that indicates whether the MessageFault has a detail object.

IsMustUnderstandFault IsMustUnderstandFault IsMustUnderstandFault IsMustUnderstandFault

Gets a value indicating whether this fault was caused by the failure to understand a SOAP header.

Node Node Node Node

Gets the SOAP node containing information about which SOAP node on a message path cause the fault.

Reason Reason Reason Reason

Gets a textual description of a SOAP fault.

Methods

CreateFault(FaultCode, FaultReason) CreateFault(FaultCode, FaultReason) CreateFault(FaultCode, FaultReason) CreateFault(FaultCode, FaultReason)

Returns a new MessageFault object that uses the specified FaultCode and FaultReason objects.

CreateFault(FaultCode, FaultReason, Object) CreateFault(FaultCode, FaultReason, Object) CreateFault(FaultCode, FaultReason, Object) CreateFault(FaultCode, FaultReason, Object)

Returns a new MessageFault object that uses the specified FaultCode, FaultReason, and detail object.

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

Returns a new MessageFault object that uses the specified FaultCode, FaultReason, detail object, and XmlObjectSerializer objects.

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

Returns a new MessageFault object that uses the specified FaultCode, FaultReason, detail object, XmlObjectSerializer, and actor.

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

Returns a new MessageFault object that uses the specified FaultCode, FaultReason, detail object, XmlObjectSerializer, actor, and node values.

CreateFault(FaultCode, String) CreateFault(FaultCode, String) CreateFault(FaultCode, String) CreateFault(FaultCode, String)

Returns a new MessageFault object that uses the specified FaultCode and fault reason.

CreateFault(Message, Int32) CreateFault(Message, Int32) CreateFault(Message, Int32) CreateFault(Message, Int32)

Returns a new MessageFault object that uses the specified Message and the specified maximum buffer size for the message buffer.

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

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetDetail<T>() GetDetail<T>() GetDetail<T>() GetDetail<T>()

Returns the detail object of the message fault.

GetDetail<T>(XmlObjectSerializer) GetDetail<T>(XmlObjectSerializer) GetDetail<T>(XmlObjectSerializer) GetDetail<T>(XmlObjectSerializer)

Returns the detail object that uses the specified XmlObjectSerializer.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetReaderAtDetailContents() GetReaderAtDetailContents() GetReaderAtDetailContents() GetReaderAtDetailContents()

Returns an XmlDictionaryReader object that is positioned on the detail object of the MessageFault.

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

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
OnGetReaderAtDetailContents() OnGetReaderAtDetailContents() OnGetReaderAtDetailContents() OnGetReaderAtDetailContents()

When called in a derived class, returns an XmlDictionaryReader object that is positioned on the detail object of the MessageFault.

OnWriteDetail(XmlDictionaryWriter, EnvelopeVersion) OnWriteDetail(XmlDictionaryWriter, EnvelopeVersion) OnWriteDetail(XmlDictionaryWriter, EnvelopeVersion) OnWriteDetail(XmlDictionaryWriter, EnvelopeVersion)

Invoked prior to writing the detail contents.

OnWriteDetailContents(XmlDictionaryWriter) OnWriteDetailContents(XmlDictionaryWriter) OnWriteDetailContents(XmlDictionaryWriter) OnWriteDetailContents(XmlDictionaryWriter)

When overridden in a non-abstract derived class, writes the contents of the detail element.

OnWriteStartDetail(XmlDictionaryWriter, EnvelopeVersion) OnWriteStartDetail(XmlDictionaryWriter, EnvelopeVersion) OnWriteStartDetail(XmlDictionaryWriter, EnvelopeVersion) OnWriteStartDetail(XmlDictionaryWriter, EnvelopeVersion)

Writes the start element using the specified XmlDictionaryWriter and SOAP envelope version.

ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)
WasHeaderNotUnderstood(MessageHeaders, String, String) WasHeaderNotUnderstood(MessageHeaders, String, String) WasHeaderNotUnderstood(MessageHeaders, String, String) WasHeaderNotUnderstood(MessageHeaders, String, String)

Gets a value indicating whether the SOAP message headers were understood.

WriteTo(XmlDictionaryWriter, EnvelopeVersion) WriteTo(XmlDictionaryWriter, EnvelopeVersion) WriteTo(XmlDictionaryWriter, EnvelopeVersion) WriteTo(XmlDictionaryWriter, EnvelopeVersion)

Writes the message fault that uses the specified XmlDictionaryWriter and SOAP envelope version.

WriteTo(XmlWriter, EnvelopeVersion) WriteTo(XmlWriter, EnvelopeVersion) WriteTo(XmlWriter, EnvelopeVersion) WriteTo(XmlWriter, EnvelopeVersion)

Writes the message fault that uses the specified XmlWriter and SOAP envelope version.

Applies to