MessageFault Class
TOC
Collapse the table of content
Expand the table of content

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.

Namespace:   System.ServiceModel.Channels
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

System.Object
  System.ServiceModel.Channels.MessageFault

public abstract class MessageFault

NameDescription
System_CAPS_protmethodMessageFault()

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

NameDescription
System_CAPS_pubpropertyActor

Gets or sets the value of the actor.

System_CAPS_pubpropertyCode

Gets the SOAP fault code.

System_CAPS_pubpropertyHasDetail

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

System_CAPS_pubpropertyIsMustUnderstandFault

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

System_CAPS_pubpropertyNode

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

System_CAPS_pubpropertyReason

Gets a textual description of a SOAP fault.

NameDescription
System_CAPS_pubmethodSystem_CAPS_staticCreateFault(FaultCode, FaultReason)

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

System_CAPS_pubmethodSystem_CAPS_staticCreateFault(FaultCode, FaultReason, Object)

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

System_CAPS_pubmethodSystem_CAPS_staticCreateFault(FaultCode, FaultReason, Object, XmlObjectSerializer)

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

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

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

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

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

System_CAPS_pubmethodSystem_CAPS_staticCreateFault(FaultCode, String)

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

System_CAPS_pubmethodSystem_CAPS_staticCreateFault(Message, Int32)

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

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetDetail<T>()

Returns the detail object of the message fault.

System_CAPS_pubmethodGetDetail<T>(XmlObjectSerializer)

Returns the detail object that uses the specified XmlObjectSerializer.

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetReaderAtDetailContents()

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

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_protmethodOnGetReaderAtDetailContents()

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

System_CAPS_protmethodOnWriteDetail(XmlDictionaryWriter, EnvelopeVersion)

Invoked prior to writing the detail contents.

System_CAPS_protmethodOnWriteDetailContents(XmlDictionaryWriter)

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

System_CAPS_protmethodOnWriteStartDetail(XmlDictionaryWriter, EnvelopeVersion)

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

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

System_CAPS_pubmethodSystem_CAPS_staticWasHeaderNotUnderstood(MessageHeaders, String, String)

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

System_CAPS_pubmethodWriteTo(XmlDictionaryWriter, EnvelopeVersion)

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

System_CAPS_pubmethodWriteTo(XmlWriter, EnvelopeVersion)

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

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

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 3.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 3.0
Windows Phone Silverlight
Available since 7.0

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show:
© 2016 Microsoft