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)
void ProvideFault( Exception^ error, MessageVersion^ version, Message^% fault )
- Type: System.ServiceModel.Channels::MessageVersion
The SOAP version of the message.
Implement the method to create a custom fault message that is returned to the client. The 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 implementations have been called, the fault message is sent back to the client (if fault is non-nullptr). If the fault parameter is nullptr the default fault is sent to the client.
The inbound message that caused the processing error is available during this method from the OperationContext::RequestContext property.
Because the 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 method being called on the operation thread.
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.
<configuration> <system.serviceModel> <services> <service name="Microsoft.WCF.Documentation.SampleService" behaviorConfiguration="metaAndErrors"> <host> <baseAddresses> <add baseAddress="http://localhost:8080/SampleService"/> </baseAddresses> </host> <endpoint address="" binding="wsHttpBinding" contract="Microsoft.WCF.Documentation.ISampleService" /> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> <behaviors> <serviceBehaviors> <behavior name="metaAndErrors"> <serviceDebug includeExceptionDetailInFaults="true"/> <serviceMetadata httpGetEnabled="true"/> <enforceGreetingFaults /> </behavior> </serviceBehaviors> </behaviors> <extensions> <behaviorExtensions> <add name="enforceGreetingFaults" type="Microsoft.WCF.Documentation.EnforceGreetingFaultBehavior, HostApplication, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" /> </behaviorExtensions> </extensions> </system.serviceModel> </configuration>