編輯

共用方式為


FaultException<TDetail> Constructors

Definition

Initializes a new instance of the FaultException<TDetail> class.

Overloads

FaultException<TDetail>(TDetail)

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

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)

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

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)

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)

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)

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)

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)

Source:
FaultException.cs
Source:
FaultException.cs

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
TDetail

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.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.

Applies to

FaultException<TDetail>(SerializationInfo, StreamingContext)

Source:
FaultException.cs
Source:
FaultException.cs

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

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

context
StreamingContext

The stream from which to reconstruct the FaultException object.

Applies to

FaultException<TDetail>(TDetail, FaultReason)

Source:
FaultException.cs
Source:
FaultException.cs

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
TDetail

The object used as the SOAP fault detail.

reason
FaultReason

The reason for the SOAP fault.

Applies to

FaultException<TDetail>(TDetail, String)

Source:
FaultException.cs
Source:
FaultException.cs

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
TDetail

The object used as the SOAP fault detail.

reason
String

The reason for the SOAP fault.

Applies to

FaultException<TDetail>(TDetail, FaultReason, FaultCode)

Source:
FaultException.cs
Source:
FaultException.cs

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
TDetail

The object used as the SOAP fault detail.

reason
FaultReason

The reason for the SOAP fault.

code
FaultCode

The fault code for the SOAP fault.

Applies to

FaultException<TDetail>(TDetail, String, FaultCode)

Source:
FaultException.cs
Source:
FaultException.cs

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
TDetail

The object used as the SOAP fault detail.

reason
String

The reason for the SOAP fault.

code
FaultCode

The fault code for the SOAP fault.

Applies to

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

Source:
FaultException.cs
Source:
FaultException.cs

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
TDetail

The object used as the SOAP fault detail.

reason
FaultReason

The reason for the SOAP fault.

code
FaultCode

The fault code for the SOAP fault.

action
String

The action of the SOAP fault.

Applies to

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

Source:
FaultException.cs
Source:
FaultException.cs

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
TDetail

The object used as the SOAP fault detail.

reason
String

The reason for the SOAP fault.

code
FaultCode

The fault code for the SOAP fault.

action
String

The action of the SOAP fault.

Applies to