共用方式為


FaultException<TDetail> 建構函式

定義

初始化 FaultException<TDetail> 類別的新執行個體。

多載

FaultException<TDetail>(TDetail)

初始化 FaultException<TDetail> 類別的新執行個體,這個執行個體使用指定的詳細資料物件。

FaultException<TDetail>(SerializationInfo, StreamingContext)

將資料流還原序列化至 FaultException<TDetail> 物件時,使用指定的序列化資訊和內容,初始化 FaultException 類別的新執行個體。

FaultException<TDetail>(TDetail, FaultReason)

初始化 FaultException<TDetail> 類別的新執行個體,這個執行個體使用指定的詳細資料物件和錯誤原因。

FaultException<TDetail>(TDetail, String)

初始化 FaultException<TDetail> 類別的新執行個體,這個執行個體使用指定的詳細資料和錯誤原因。

FaultException<TDetail>(TDetail, FaultReason, FaultCode)

初始化 FaultException<TDetail> 類別的新執行個體,這個執行個體使用指定的詳細資料物件、錯誤原因和錯誤碼。

FaultException<TDetail>(TDetail, String, FaultCode)

初始化 FaultException<TDetail> 類別的新執行個體,這個執行個體使用指定的詳細資料物件、錯誤原因和錯誤碼。

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

初始化 FaultException<TDetail> 類別的新執行個體,這個執行個體使用指定的詳細資料物件、SOAP 錯誤原因、錯誤碼和動作值。

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

初始化 FaultException<TDetail> 類別的新執行個體,這個執行個體使用指定的詳細資料物件、SOAP 錯誤原因、錯誤碼和動作值。

FaultException<TDetail>(TDetail)

初始化 FaultException<TDetail> 類別的新執行個體,這個執行個體使用指定的詳細資料物件。

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

參數

detail
TDetail

當做 SOAP 錯誤詳細資料使用的物件。

範例

下列程式碼範例示範服務如何使用 FaultException<TDetail> 型別,擲回轉換成由 FaultContractAttribute 所指定之 SOAP 錯誤的 Managed 例外狀況。

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

備註

詳細資料物件必須是可序列化的,否則會在序列化 FaultException<TDetail> 時擲回例外狀況。

適用於

FaultException<TDetail>(SerializationInfo, StreamingContext)

將資料流還原序列化至 FaultException<TDetail> 物件時,使用指定的序列化資訊和內容,初始化 FaultException 類別的新執行個體。

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)

參數

info
SerializationInfo

FaultException 重新建構 context 物件必要的序列化資訊。

context
StreamingContext

從其重新建構 FaultException 物件的資料流。

適用於

FaultException<TDetail>(TDetail, FaultReason)

初始化 FaultException<TDetail> 類別的新執行個體,這個執行個體使用指定的詳細資料物件和錯誤原因。

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)

參數

detail
TDetail

當做 SOAP 錯誤詳細資料使用的物件。

reason
FaultReason

SOAP 錯誤的原因。

適用於

FaultException<TDetail>(TDetail, String)

初始化 FaultException<TDetail> 類別的新執行個體,這個執行個體使用指定的詳細資料和錯誤原因。

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)

參數

detail
TDetail

當做 SOAP 錯誤詳細資料使用的物件。

reason
String

SOAP 錯誤的原因。

適用於

FaultException<TDetail>(TDetail, FaultReason, FaultCode)

初始化 FaultException<TDetail> 類別的新執行個體,這個執行個體使用指定的詳細資料物件、錯誤原因和錯誤碼。

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)

參數

detail
TDetail

當做 SOAP 錯誤詳細資料使用的物件。

reason
FaultReason

SOAP 錯誤的原因。

code
FaultCode

SOAP 錯誤的錯誤碼。

適用於

FaultException<TDetail>(TDetail, String, FaultCode)

初始化 FaultException<TDetail> 類別的新執行個體,這個執行個體使用指定的詳細資料物件、錯誤原因和錯誤碼。

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)

參數

detail
TDetail

當做 SOAP 錯誤詳細資料使用的物件。

reason
String

SOAP 錯誤的原因。

code
FaultCode

SOAP 錯誤的錯誤碼。

適用於

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

初始化 FaultException<TDetail> 類別的新執行個體,這個執行個體使用指定的詳細資料物件、SOAP 錯誤原因、錯誤碼和動作值。

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)

參數

detail
TDetail

當做 SOAP 錯誤詳細資料使用的物件。

reason
FaultReason

SOAP 錯誤的原因。

code
FaultCode

SOAP 錯誤的錯誤碼。

action
String

SOAP 錯誤的動作。

適用於

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

初始化 FaultException<TDetail> 類別的新執行個體,這個執行個體使用指定的詳細資料物件、SOAP 錯誤原因、錯誤碼和動作值。

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)

參數

detail
TDetail

當做 SOAP 錯誤詳細資料使用的物件。

reason
String

SOAP 錯誤的原因。

code
FaultCode

SOAP 錯誤的錯誤碼。

action
String

SOAP 錯誤的動作。

適用於