FaultException<TDetail> 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
클라이언트 애플리케이션에서 계약에 지정된 SOAP 오류를 catch하는 데 사용됩니다.
generic <typename TDetail>
public ref class FaultException : System::ServiceModel::FaultException
public class FaultException<TDetail> : System.ServiceModel.FaultException
[System.Runtime.Serialization.KnownType("GetKnownTypes")]
[System.Serializable]
public class FaultException<TDetail> : System.ServiceModel.FaultException
[System.Serializable]
public class FaultException<TDetail> : System.ServiceModel.FaultException
type FaultException<'Detail> = class
inherit FaultException
[<System.Runtime.Serialization.KnownType("GetKnownTypes")>]
[<System.Serializable>]
type FaultException<'Detail> = class
inherit FaultException
[<System.Serializable>]
type FaultException<'Detail> = class
inherit FaultException
Public Class FaultException(Of TDetail)
Inherits FaultException
형식 매개 변수
- TDetail
serialize할 수 있는 오류 세부 유형입니다.
- 상속
- 상속
- 파생
- 특성
예제
다음 코드 예제에서는 서비스에서 형식을 사용하여 FaultException<TDetail> 에서 지정한 SOAP 오류로 변환되는 관리되는 예외를 FaultContractAttributethrow하는 방법을 보여 있습니다.
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
다음 코드 예제에서는 ServiceModel 메타데이터 유틸리티 도구(Svcutil.exe)를 사용하여 클라이언트에서 가져올 때 클라이언트 코드의 모양을 보여 줍니다.
다음 코드 예제에서는 클라이언트가 작업 계약에 지정된 사용자 지정 SOAP 오류를 나타내는 형식을 catch FaultException<TDetail> 하는 방법을 보여 줍니다.
using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using Microsoft.WCF.Documentation;
public class Client
{
public static void Main()
{
// Picks up configuration from the config file.
SampleServiceClient wcfClient = new SampleServiceClient();
try
{
// Making calls.
Console.WriteLine("Enter the greeting to send: ");
string greeting = Console.ReadLine();
Console.WriteLine("The service responded: " + wcfClient.SampleMethod(greeting));
Console.WriteLine("Press ENTER to exit:");
Console.ReadLine();
// Done with service.
wcfClient.Close();
Console.WriteLine("Done!");
}
catch (TimeoutException timeProblem)
{
Console.WriteLine("The service operation timed out. " + timeProblem.Message);
Console.ReadLine();
wcfClient.Abort();
}
catch (FaultException<GreetingFault> greetingFault)
{
Console.WriteLine(greetingFault.Detail.Message);
Console.ReadLine();
wcfClient.Abort();
}
catch (FaultException unknownFault)
{
Console.WriteLine("An unknown exception was received. " + unknownFault.Message);
Console.ReadLine();
wcfClient.Abort();
}
catch (CommunicationException commProblem)
{
Console.WriteLine("There was a communication problem. " + commProblem.Message + commProblem.StackTrace);
Console.ReadLine();
wcfClient.Abort();
}
}
}
Imports System.ServiceModel
Imports System.ServiceModel.Channels
Imports Microsoft.WCF.Documentation
Public Class Client
Public Shared Sub Main()
' Picks up configuration from the config file.
Dim wcfClient As New SampleServiceClient()
Try
' Making calls.
Console.WriteLine("Enter the greeting to send: ")
Dim greeting As String = Console.ReadLine()
Console.WriteLine("The service responded: " & wcfClient.SampleMethod(greeting))
Console.WriteLine("Press ENTER to exit:")
Console.ReadLine()
' Done with service.
wcfClient.Close()
Console.WriteLine("Done!")
Catch timeProblem As TimeoutException
Console.WriteLine("The service operation timed out. " & timeProblem.Message)
Console.ReadLine()
wcfClient.Abort()
Catch greetingFault As FaultException(Of GreetingFault)
Console.WriteLine(greetingFault.Detail.Message)
Console.ReadLine()
wcfClient.Abort()
Catch unknownFault As FaultException
Console.WriteLine("An unknown exception was received. " & unknownFault.Message)
Console.ReadLine()
wcfClient.Abort()
Catch commProblem As CommunicationException
Console.WriteLine("There was a communication problem. " & commProblem.Message + commProblem.StackTrace)
Console.ReadLine()
wcfClient.Abort()
End Try
End Sub
End Class
설명
Catch 된 FaultException<TDetail> Windows Communication Foundation (WCF) 클라이언트 애플리케이션 작업 계약의 지정 된 SOAP 오류를 처리 하는 개체입니다.
일반적인 배포된 서비스는 를 FaultContractAttribute 사용하여 정상적인 작업 과정에서 클라이언트가 받을 것으로 예상할 수 있는 모든 SOAP 오류를 공식적으로 지정합니다. 오류 정보를 FaultContractAttribute 으로 표시 됩니다를 FaultException<TDetail> (여기서는 typeparameter는 작업에 지정 된 직렬화 가능 오류 개체 FaultContractAttribute) 클라이언트 애플리케이션에 도착할 때. 는 FaultContractAttribute 양방향 서비스 메서드와 비동기 메서드 쌍 모두에 SOAP 오류를 지정하는 데 사용할 수 있습니다.
FaultException<TDetail> 는 및 따라서 CommunicationException모두 FaultException 이므로 지정된 SOAP 오류를 catch하려면 및 CommunicationException 형식 이전에 FaultException 형식을 catch FaultException<TDetail> 하거나 해당 예외 처리기 중 하나에서 지정된 예외를 처리해야 합니다.
참고
System.ServiceModel.FaultContractAttribute를 사용하여 형식 매개 변수가 FaultException<TDetail>인 System.String을 지정하면 문자열 값이 클라이언트 애플리케이션의 Detail 속성에 할당되므로 클라이언트가 FaultException<TDetail>.ToString 메서드를 호출하여 해당 문자열을 가져올 수 없습니다. 클라이언트 애플리케이션이 Exception.ToString을 호출할 때 문자열 값이 반환되도록 하려면 작업 내에서 System.ServiceModel.FaultException 예외를 throw하고 문자열을 생성자에 전달합니다. 일반적으로 세부 정보 형식은 오류가 아닌 오류에 적합한 사용자 지정 직렬화 가능 형식이 System.String되는 것이 좋습니다.
생성자
속성
| Action |
오류 메시지의 SOAP 동작 값을 가져옵니다. (다음에서 상속됨 FaultException) |
| Code |
SOAP 오류에 대한 오류 코드를 가져옵니다. (다음에서 상속됨 FaultException) |
| Data |
예외에 대한 사용자 정의 정보를 추가로 제공하는 키/값 쌍 컬렉션을 가져옵니다. (다음에서 상속됨 Exception) |
| Detail |
오류 조건의 세부 정보가 포함된 개체를 가져옵니다. |
| HelpLink |
이 예외와 연결된 도움말 파일에 대한 링크를 가져오거나 설정합니다. (다음에서 상속됨 Exception) |
| HResult |
특정 예외에 할당된 코드화된 숫자 값인 HRESULT를 가져오거나 설정합니다. (다음에서 상속됨 Exception) |
| InnerException |
현재 예외를 발생시킨 Exception 인스턴스를 가져옵니다. (다음에서 상속됨 Exception) |
| Message |
예외에 대한 메시지를 가져옵니다. (다음에서 상속됨 FaultException) |
| Reason |
SOAP 오류의 FaultReason을 가져옵니다. (다음에서 상속됨 FaultException) |
| Source |
오류를 발생시키는 애플리케이션 또는 개체의 이름을 가져오거나 설정합니다. (다음에서 상속됨 Exception) |
| StackTrace |
호출 스택의 직접 실행 프레임 문자열 표현을 가져옵니다. (다음에서 상속됨 Exception) |
| TargetSite |
현재 예외를 throw하는 메서드를 가져옵니다. (다음에서 상속됨 Exception) |
메서드
| CreateMessageFault() |
SOAP 오류를 나타내는 MessageFault를 만드는 데 사용할 수 있는 Message 개체를 만듭니다. |
| Equals(Object) |
지정된 개체가 현재 개체와 같은지 확인합니다. (다음에서 상속됨 Object) |
| GetBaseException() |
파생 클래스에서 재정의된 경우 하나 이상의 후속 예외의 근본 원인이 되는 Exception 을 반환합니다. (다음에서 상속됨 Exception) |
| GetHashCode() |
기본 해시 함수로 작동합니다. (다음에서 상속됨 Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
사용되지 않음.
개체가 스트림으로 serialize될 때 호출되는 GetObjectData(SerializationInfo, StreamingContext) 메서드의 구현입니다. |
| GetObjectData(SerializationInfo, StreamingContext) |
사용되지 않음.
개체가 스트림으로 serialize될 때 호출되는 GetObjectData(SerializationInfo, StreamingContext) 메서드의 구현입니다. (다음에서 상속됨 FaultException) |
| GetType() |
현재 인스턴스의 런타임 형식을 가져옵니다. (다음에서 상속됨 Exception) |
| MemberwiseClone() |
현재 Object의 단순 복사본을 만듭니다. (다음에서 상속됨 Object) |
| ToString() |
FaultException<TDetail> 개체의 문자열을 반환합니다. |
이벤트
| SerializeObjectState |
사용되지 않음.
예외에 대한 serialize된 데이터가 들어 있는 예외 상태 개체가 만들어지도록 예외가 serialize될 때 발생합니다. (다음에서 상속됨 Exception) |