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.

  NameDescription
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsMessageFaultWhen called in a derived class, initializes a new instance of the MessageFault class.
Top

  NameDescription
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsActorGets or sets the value of the actor.
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsCodeGets the SOAP fault code.
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsHasDetailGets a value that indicates whether the MessageFault has a detail object.
Public propertyIsMustUnderstandFaultGets a value indicating whether this fault was caused by the failure to understand a SOAP header.
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsNodeGets the SOAP node containing information about which SOAP node on a message path cause the fault.
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsReasonGets a textual description of a SOAP fault.
Top

  NameDescription
Public methodStatic memberCreateFault(FaultCode, FaultReason)Returns a new MessageFault object that uses the specified FaultCode and FaultReason objects.
Public methodStatic memberCreateFault(FaultCode, String)Returns a new MessageFault object that uses the specified FaultCode and fault reason.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsCreateFault(Message, Int32)Returns a new MessageFault object that uses the specified Message and the specified maximum buffer size for the message buffer.
Public methodStatic memberCreateFault(FaultCode, FaultReason, Object)Returns a new MessageFault object that uses the specified FaultCode, FaultReason, and detail object.
Public methodStatic memberCreateFault(FaultCode, FaultReason, Object, XmlObjectSerializer)Returns a new MessageFault object that uses the specified FaultCode, FaultReason, detail object, and XmlObjectSerializer objects.
Public methodStatic memberCreateFault(FaultCode, FaultReason, Object, XmlObjectSerializer, String)Returns a new MessageFault object that uses the specified FaultCode, FaultReason, detail object, XmlObjectSerializer, and actor.
Public methodStatic memberCreateFault(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 methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetDetail<T>()Returns the detail object of the message fault.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetDetail<T>(XmlObjectSerializer)Returns the detail object that uses the specified XmlObjectSerializer.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetReaderAtDetailContentsReturns an XmlDictionaryReader object that is positioned on the detail object of the MessageFault.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsOnGetReaderAtDetailContentsWhen called in a derived class, returns an XmlDictionaryReader object that is positioned on the detail object of the MessageFault.
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsOnWriteDetailInvoked prior to writing the detail contents.
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsOnWriteDetailContentsWhen overridden in a non-abstract derived class, writes the contents of the detail element.
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsOnWriteStartDetailWrites the start element using the specified XmlDictionaryWriter and SOAP envelope version.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodStatic memberWasHeaderNotUnderstoodGets a value indicating whether the SOAP message headers were understood.
Public methodWriteTo(XmlDictionaryWriter, EnvelopeVersion)Writes the message fault that uses the specified XmlDictionaryWriter and SOAP envelope version.
Public methodWriteTo(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, 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.

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

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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.
Show:
© 2014 Microsoft