IErrorHandler::ProvideFault Method (Exception^, MessageVersion^, Message^%)
Enables the creation of a custom FaultException<TDetail> that is returned from an exception in the course of a service method.
Assembly: System.ServiceModel (in System.ServiceModel.dll)
Parameters
- error
-
Type:
System::Exception^
The Exception object thrown in the course of the service operation.
- version
-
Type:
System.ServiceModel.Channels::MessageVersion^
The SOAP version of the message.
- fault
-
Type:
System.ServiceModel.Channels::Message^%
The System.ServiceModel.Channels::Message object that is returned to the client, or service, in the duplex case.
Implement the ProvideFault method to create a custom fault message that is returned to the client. The ProvideFault method will always be called for exceptions that leave operations, except when the WCF runtime recognizes the exception as especially fatal and rethrows the exception itself. When all ProvideFault implementations have been called, the fault message is sent back to the client (if fault is non-null). If the fault parameter is null the default fault is sent to the client.
Note |
|---|
The inbound message that caused the processing error is available during this method from the OperationContext::RequestContext property. |
Note |
|---|
Because the ProvideFault method can be called from many different places there are no guarantees made about which thread the method is called on. Do not depend on ProvideFault method being called on the operation thread. |
The following code example demonstrates a service that implements IErrorHandler that returns only FaultException<TDetail> of type GreetingFault when a service method throws a managed exception.
The following code example shows how to use a service behavior to add the IErrorHandler implementation to the ErrorHandlers property.
The following code example shows how to configure the service to load the service behavior using an application configuration file. For more details about how to expose a service behavior in a configuration file, see IServiceBehavior.
Available since 3.0
