FaultException<TDetail> 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 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)
- Source:
- FaultException.cs
- Source:
- FaultException.cs
- Source:
- FaultException.cs
初始化使用指定详细信息对象的 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 错误的托管异常。
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)
- Source:
- FaultException.cs
- Source:
- FaultException.cs
- Source:
- FaultException.cs
在将流反序列化到 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)
- Source:
- FaultException.cs
- Source:
- FaultException.cs
- Source:
- FaultException.cs
初始化使用指定详细信息对象和错误原因的 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)
- Source:
- FaultException.cs
- Source:
- FaultException.cs
- Source:
- FaultException.cs
初始化使用指定详细信息和错误原因的 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)
- Source:
- FaultException.cs
- Source:
- FaultException.cs
- Source:
- FaultException.cs
初始化 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)
- Source:
- FaultException.cs
- Source:
- FaultException.cs
- Source:
- FaultException.cs
初始化 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)
- Source:
- FaultException.cs
- Source:
- FaultException.cs
- Source:
- FaultException.cs
初始化 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)
- Source:
- FaultException.cs
- Source:
- FaultException.cs
- Source:
- FaultException.cs
初始化 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 错误的操作。