FaultException<TDetail> FaultException<TDetail> FaultException<TDetail> FaultException<TDetail> Constructors

Definition

Overloads

FaultException<TDetail>(TDetail) FaultException<TDetail>(TDetail) FaultException<TDetail>(TDetail) FaultException<TDetail>(TDetail)

Initializes a new instance of the FaultException<TDetail> class that uses the specified detail object.

FaultException<TDetail>(SerializationInfo, StreamingContext) FaultException<TDetail>(SerializationInfo, StreamingContext) FaultException<TDetail>(SerializationInfo, StreamingContext) FaultException<TDetail>(SerializationInfo, StreamingContext)

Initializes a new instance of the FaultException<TDetail> class using the specified serialization information and context when deserializing a stream into a FaultException object.

FaultException<TDetail>(TDetail, FaultReason) FaultException<TDetail>(TDetail, FaultReason) FaultException<TDetail>(TDetail, FaultReason) FaultException<TDetail>(TDetail, FaultReason)

Initializes a new instance of the FaultException<TDetail> class that uses the specified detail object and fault reason.

FaultException<TDetail>(TDetail, String) FaultException<TDetail>(TDetail, String) FaultException<TDetail>(TDetail, String) FaultException<TDetail>(TDetail, String)

Initializes a new instance of the FaultException<TDetail> class that uses the specified detail and fault reason.

FaultException<TDetail>(TDetail, FaultReason, FaultCode) FaultException<TDetail>(TDetail, FaultReason, FaultCode) FaultException<TDetail>(TDetail, FaultReason, FaultCode) FaultException<TDetail>(TDetail, FaultReason, FaultCode)

Initializes a new instance of the FaultException<TDetail> class that uses the specified detail object, fault reason, and fault code.

FaultException<TDetail>(TDetail, String, FaultCode) FaultException<TDetail>(TDetail, String, FaultCode) FaultException<TDetail>(TDetail, String, FaultCode) FaultException<TDetail>(TDetail, String, FaultCode)

Initializes a new instance of the FaultException<TDetail> class that uses the specified detail object, fault reason, and fault code.

FaultException<TDetail>(TDetail, FaultReason, FaultCode, String) FaultException<TDetail>(TDetail, FaultReason, FaultCode, String) FaultException<TDetail>(TDetail, FaultReason, FaultCode, String) FaultException<TDetail>(TDetail, FaultReason, FaultCode, String)

Initializes a new instance of the FaultException<TDetail> class that uses the specified detail object, and SOAP fault reason, code and action values.

FaultException<TDetail>(TDetail, String, FaultCode, String) FaultException<TDetail>(TDetail, String, FaultCode, String) FaultException<TDetail>(TDetail, String, FaultCode, String) FaultException<TDetail>(TDetail, String, FaultCode, String)

Initializes a new instance of the FaultException<TDetail> class that uses the specified detail object, and SOAP fault reason, code and action values.

FaultException<TDetail>(TDetail) FaultException<TDetail>(TDetail) FaultException<TDetail>(TDetail) FaultException<TDetail>(TDetail)

Initializes a new instance of the FaultException<TDetail> class that uses the specified detail object.

public:
 FaultException(TDetail detail);
public FaultException (TDetail detail);
new System.ServiceModel.FaultException<'Detail> : 'Detail -> System.ServiceModel.FaultException<'Detail>
Public Sub New (detail As TDetail)
Parameters
detail

The object used as the SOAP fault detail.

Examples

The following code example shows how a service uses the FaultException<TDetail> type to throw a managed exception that gets converted into the SOAP fault specified by the FaultContractAttribute.

using System;
using System.Collections.Generic;
using System.Net.Security;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace Microsoft.WCF.Documentation
{
  [ServiceContract(Namespace="http://microsoft.wcf.documentation")]
  public interface ISampleService{
    [OperationContract]
    [FaultContractAttribute(
      typeof(GreetingFault),
      Action="http://www.contoso.com/GreetingFault",
      ProtectionLevel=ProtectionLevel.EncryptAndSign
      )]
    string SampleMethod(string msg);
  }
 
  [DataContractAttribute]
  public class GreetingFault
  { 
    private string report;

    public GreetingFault(string message)
    {
      this.report = message;
    }

    [DataMemberAttribute]
    public string Message
    {
      get { return this.report; }
      set { this.report = value; }
    }
  }

  class SampleService : ISampleService
  {
  #region ISampleService Members

  public string  SampleMethod(string msg)
  {
    Console.WriteLine("Client said: " + msg);
    // Generate intermittent error behavior.
    Random rnd = new Random(DateTime.Now.Millisecond);
    int test = rnd.Next(5);
    if (test % 2 != 0)
      return "The service greets you: " + msg; 
    else
      throw new FaultException<GreetingFault>(new GreetingFault("A Greeting error occurred. You said: " + msg));
  }

  #endregion
  }
}

Imports System
Imports System.Collections.Generic
Imports System.Net.Security
Imports System.Runtime.Serialization
Imports System.ServiceModel
Imports System.Text

Namespace Microsoft.WCF.Documentation
  <ServiceContract(Namespace:="http://microsoft.wcf.documentation")> _
  Public Interface ISampleService
	<OperationContract, FaultContractAttribute(GetType(GreetingFault), Action:="http://www.contoso.com/GreetingFault", ProtectionLevel:=ProtectionLevel.EncryptAndSign)> _
	Function SampleMethod(ByVal msg As String) As String
  End Interface

  <DataContractAttribute> _
  Public Class GreetingFault
	Private report As String

	Public Sub New(ByVal message As String)
	  Me.report = message
	End Sub

	<DataMemberAttribute> _
	Public Property Message() As String
	  Get
		  Return Me.report
	  End Get
	  Set(ByVal value As String)
		  Me.report = value
	  End Set
	End Property
  End Class

  Friend Class SampleService
	  Implements ISampleService
  #Region "ISampleService Members"

  Public Function SampleMethod(ByVal msg As String) As String Implements ISampleService.SampleMethod
	Console.WriteLine("Client said: " & msg)
	' Generate intermittent error behavior.
	Dim rand As New Random(DateTime.Now.Millisecond)
	Dim test As Integer = rand.Next(5)
	If test Mod 2 <> 0 Then
	  Return "The service greets you: " & msg
	Else
	  Throw New FaultException(Of GreetingFault)(New GreetingFault("A Greeting error occurred. You said: " & msg))
	End If
  End Function

  #End Region
  End Class
End Namespace

Remarks

The detail object must be serializable or an exception is thrown when the FaultException<TDetail> is serialized.

FaultException<TDetail>(SerializationInfo, StreamingContext) FaultException<TDetail>(SerializationInfo, StreamingContext) FaultException<TDetail>(SerializationInfo, StreamingContext) FaultException<TDetail>(SerializationInfo, StreamingContext)

Initializes a new instance of the FaultException<TDetail> class using the specified serialization information and context when deserializing a stream into a FaultException object.

protected:
 FaultException(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
protected FaultException (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
new System.ServiceModel.FaultException<'Detail> : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.ServiceModel.FaultException<'Detail>
Protected Sub New (info As SerializationInfo, context As StreamingContext)
Parameters
info
SerializationInfo SerializationInfo SerializationInfo SerializationInfo

The serialization information necessary to reconstruct the FaultException object from the context.

context
StreamingContext StreamingContext StreamingContext StreamingContext

The stream from which to reconstruct the FaultException object.

FaultException<TDetail>(TDetail, FaultReason) FaultException<TDetail>(TDetail, FaultReason) FaultException<TDetail>(TDetail, FaultReason) FaultException<TDetail>(TDetail, FaultReason)

Initializes a new instance of the FaultException<TDetail> class that uses the specified detail object and fault reason.

public:
 FaultException(TDetail detail, System::ServiceModel::FaultReason ^ reason);
public FaultException (TDetail detail, System.ServiceModel.FaultReason reason);
new System.ServiceModel.FaultException<'Detail> : 'Detail * System.ServiceModel.FaultReason -> System.ServiceModel.FaultException<'Detail>
Public Sub New (detail As TDetail, reason As FaultReason)
Parameters
detail

The object used as the SOAP fault detail.

reason
FaultReason FaultReason FaultReason FaultReason

The reason for the SOAP fault.

FaultException<TDetail>(TDetail, String) FaultException<TDetail>(TDetail, String) FaultException<TDetail>(TDetail, String) FaultException<TDetail>(TDetail, String)

Initializes a new instance of the FaultException<TDetail> class that uses the specified detail and fault reason.

public:
 FaultException(TDetail detail, System::String ^ reason);
public FaultException (TDetail detail, string reason);
new System.ServiceModel.FaultException<'Detail> : 'Detail * string -> System.ServiceModel.FaultException<'Detail>
Public Sub New (detail As TDetail, reason As String)
Parameters
detail

The object used as the SOAP fault detail.

reason
String String String String

The reason for the SOAP fault.

FaultException<TDetail>(TDetail, FaultReason, FaultCode) FaultException<TDetail>(TDetail, FaultReason, FaultCode) FaultException<TDetail>(TDetail, FaultReason, FaultCode) FaultException<TDetail>(TDetail, FaultReason, FaultCode)

Initializes a new instance of the FaultException<TDetail> class that uses the specified detail object, fault reason, and fault code.

public:
 FaultException(TDetail detail, System::ServiceModel::FaultReason ^ reason, System::ServiceModel::FaultCode ^ code);
public FaultException (TDetail detail, System.ServiceModel.FaultReason reason, System.ServiceModel.FaultCode code);
new System.ServiceModel.FaultException<'Detail> : 'Detail * System.ServiceModel.FaultReason * System.ServiceModel.FaultCode -> System.ServiceModel.FaultException<'Detail>
Public Sub New (detail As TDetail, reason As FaultReason, code As FaultCode)
Parameters
detail

The object used as the SOAP fault detail.

reason
FaultReason FaultReason FaultReason FaultReason

The reason for the SOAP fault.

code
FaultCode FaultCode FaultCode FaultCode

The fault code for the SOAP fault.

FaultException<TDetail>(TDetail, String, FaultCode) FaultException<TDetail>(TDetail, String, FaultCode) FaultException<TDetail>(TDetail, String, FaultCode) FaultException<TDetail>(TDetail, String, FaultCode)

Initializes a new instance of the FaultException<TDetail> class that uses the specified detail object, fault reason, and fault code.

public:
 FaultException(TDetail detail, System::String ^ reason, System::ServiceModel::FaultCode ^ code);
public FaultException (TDetail detail, string reason, System.ServiceModel.FaultCode code);
new System.ServiceModel.FaultException<'Detail> : 'Detail * string * System.ServiceModel.FaultCode -> System.ServiceModel.FaultException<'Detail>
Public Sub New (detail As TDetail, reason As String, code As FaultCode)
Parameters
detail

The object used as the SOAP fault detail.

reason
String String String String

The reason for the SOAP fault.

code
FaultCode FaultCode FaultCode FaultCode

The fault code for the SOAP fault.

FaultException<TDetail>(TDetail, FaultReason, FaultCode, String) FaultException<TDetail>(TDetail, FaultReason, FaultCode, String) FaultException<TDetail>(TDetail, FaultReason, FaultCode, String) FaultException<TDetail>(TDetail, FaultReason, FaultCode, String)

Initializes a new instance of the FaultException<TDetail> class that uses the specified detail object, and SOAP fault reason, code and action values.

public:
 FaultException(TDetail detail, System::ServiceModel::FaultReason ^ reason, System::ServiceModel::FaultCode ^ code, System::String ^ action);
public FaultException (TDetail detail, System.ServiceModel.FaultReason reason, System.ServiceModel.FaultCode code, string action);
new System.ServiceModel.FaultException<'Detail> : 'Detail * System.ServiceModel.FaultReason * System.ServiceModel.FaultCode * string -> System.ServiceModel.FaultException<'Detail>
Public Sub New (detail As TDetail, reason As FaultReason, code As FaultCode, action As String)
Parameters
detail

The object used as the SOAP fault detail.

reason
FaultReason FaultReason FaultReason FaultReason

The reason for the SOAP fault.

code
FaultCode FaultCode FaultCode FaultCode

The fault code for the SOAP fault.

action
String String String String

The action of the SOAP fault.

FaultException<TDetail>(TDetail, String, FaultCode, String) FaultException<TDetail>(TDetail, String, FaultCode, String) FaultException<TDetail>(TDetail, String, FaultCode, String) FaultException<TDetail>(TDetail, String, FaultCode, String)

Initializes a new instance of the FaultException<TDetail> class that uses the specified detail object, and SOAP fault reason, code and action values.

public:
 FaultException(TDetail detail, System::String ^ reason, System::ServiceModel::FaultCode ^ code, System::String ^ action);
public FaultException (TDetail detail, string reason, System.ServiceModel.FaultCode code, string action);
new System.ServiceModel.FaultException<'Detail> : 'Detail * string * System.ServiceModel.FaultCode * string -> System.ServiceModel.FaultException<'Detail>
Public Sub New (detail As TDetail, reason As String, code As FaultCode, action As String)
Parameters
detail

The object used as the SOAP fault detail.

reason
String String String String

The reason for the SOAP fault.

code
FaultCode FaultCode FaultCode FaultCode

The fault code for the SOAP fault.

action
String String String String

The action of the SOAP fault.

Applies to