0 out of 1 rated this helpful - Rate this topic

MessageFault Class

Represents an in-memory representation of a SOAP fault that can be passed to CreateMessage to create a message that contains a fault.

System.Object
  System.ServiceModel.Channels.MessageFault

Namespace:  System.ServiceModel.Channels
Assembly:  System.ServiceModel (in System.ServiceModel.dll)
public abstract class MessageFault

The MessageFault type exposes the following members.

  Name Description
Protected method Supported by Portable Class Library MessageFault When called in a derived class, initializes a new instance of the MessageFault class.
Top
  Name Description
Public property Supported by Portable Class Library Actor Gets or sets the value of the actor.
Public property Supported by Portable Class Library Code Gets the SOAP fault code.
Public property Supported by Portable Class Library HasDetail Gets a value that indicates whether the MessageFault has a detail object.
Public property IsMustUnderstandFault Gets a value indicating whether this fault was caused by the failure to understand a SOAP header.
Public property Supported by Portable Class Library Node Gets the SOAP node.
Public property Supported by Portable Class Library Reason Gets a textual description of a SOAP fault.
Top
  Name Description
Public method Static member CreateFault(FaultCode, FaultReason) Returns a new MessageFault object that uses the specified FaultCode and FaultReason objects.
Public method Static member CreateFault(FaultCode, String) Returns a new MessageFault object that uses the specified FaultCode and fault reason.
Public method Static member Supported by Portable Class Library CreateFault(Message, Int32) Returns a new MessageFault object that uses the specified Message and the specified maximum buffer size for the message buffer.
Public method Static member CreateFault(FaultCode, FaultReason, Object) Returns a new MessageFault object that uses the specified FaultCode, FaultReason, and detail object.
Public method Static member CreateFault(FaultCode, FaultReason, Object, XmlObjectSerializer) Returns a new MessageFault object that uses the specified FaultCode, FaultReason, detail object, and XmlObjectSerializer objects.
Public method Static member CreateFault(FaultCode, FaultReason, Object, XmlObjectSerializer, String) Returns a new MessageFault object that uses the specified FaultCode, FaultReason, detail object, XmlObjectSerializer, and actor.
Public method Static member 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.
Public method Supported by Portable Class Library Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Supported by Portable Class Library Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method Supported by Portable Class Library GetDetail<T>() Returns the detail object of the message fault.
Public method Supported by Portable Class Library GetDetail<T>(XmlObjectSerializer) Returns the detail object that uses the specified XmlObjectSerializer.
Public method Supported by Portable Class Library GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method Supported by Portable Class Library GetReaderAtDetailContents Returns an XmlDictionaryReader object that is positioned on the detail object of the MessageFault.
Public method Supported by Portable Class Library GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method Supported by Portable Class Library MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method Supported by Portable Class Library OnGetReaderAtDetailContents When called in a derived class, returns an XmlDictionaryReader object that is positioned on the detail object of the MessageFault.
Protected method Supported by Portable Class Library OnWriteDetail Invoked prior to writing the detail contents.
Protected method Supported by Portable Class Library OnWriteDetailContents When overridden in a non-abstract derived class, writes the contents of the detail element.
Protected method Supported by Portable Class Library OnWriteStartDetail Writes the start element using the specified XmlDictionaryWriter and SOAP envelope version.
Public method Supported by Portable Class Library ToString Returns a string that represents the current object. (Inherited from Object.)
Public method Static member WasHeaderNotUnderstood Gets a value indicating whether the SOAP message headers were understood.
Public method WriteTo(XmlDictionaryWriter, EnvelopeVersion) Writes the message fault that uses the specified XmlDictionaryWriter and SOAP envelope version.
Public method WriteTo(XmlWriter, EnvelopeVersion) Writes the message fault that uses the specified XmlWriter and SOAP envelope version.
Top

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, 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.

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 .


	#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


.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ