ServiceBehaviorAttribute.IncludeExceptionDetailInFaults 속성

정의

일반적인 처리되지 않은 실행 예외를 FaultException<TDetail> 형식의 ExceptionDetail으로 변환하고 오류 메시지로 보내도록 지정하는 값을 가져오거나 설정합니다. 서비스 문제를 해결하려면 개발하는 동안에만 이 값을 true로 설정합니다.

public:
 property bool IncludeExceptionDetailInFaults { bool get(); void set(bool value); };
public bool IncludeExceptionDetailInFaults { get; set; }
member this.IncludeExceptionDetailInFaults : bool with get, set
Public Property IncludeExceptionDetailInFaults As Boolean

속성 값

Boolean

처리되지 않은 예외가 SOAP 오류로 반환되면 true이고, 그렇지 않을 경우 false입니다. 기본값은 false입니다.

예제

다음 코드 예제에서는 ServiceBehaviorAttribute 속성을 보여 줍니다. BehaviorService 클래스는 ServiceBehaviorAttribute 특성을 사용하여 다음을 나타냅니다.

  • 구현 메서드가 UI 스레드에서 호출됩니다.

  • 세션별로 서비스 개체가 하나씩 있습니다.

  • 서비스는 단일 스레드이며 재진입 호출을 지원하지 않습니다.

또한 작업 수준에서 OperationBehaviorAttribute 값은 TxWork 메서드가 흐름이 지정된 트랜잭션에 자동으로 참여하거나 작업 수행을 위해 새로운 트랜잭션을 생성함을 나타내며 처리되지 않은 예외가 발생하지 않으면 트랜잭션이 자동으로 커밋됨을 나타냅니다.

using System;
using System.ServiceModel;
using System.Transactions;

namespace Microsoft.WCF.Documentation
{
  [ServiceContract(
    Namespace="http://microsoft.wcf.documentation",
    SessionMode=SessionMode.Required
  )]
  public interface IBehaviorService
  {
    [OperationContract]
    string TxWork(string message);
  }

  // Note: To use the TransactionIsolationLevel property, you
  // must add a reference to the System.Transactions.dll assembly.
  /* The following service implementation:
   *   -- Processes messages on one thread at a time
   *   -- Creates one service object per session
   *   -- Releases the service object when the transaction commits
   */
  [ServiceBehavior(
    ConcurrencyMode=ConcurrencyMode.Single,
    InstanceContextMode=InstanceContextMode.PerSession,
    ReleaseServiceInstanceOnTransactionComplete=true
  )]
  public class BehaviorService : IBehaviorService, IDisposable
  {
    Guid myID;

    public BehaviorService()
    {
      myID = Guid.NewGuid();
      Console.WriteLine(
        "Object "
        + myID.ToString()
        + " created.");
    }

    /*
     * The following operation-level behaviors are specified:
     *   -- The executing transaction is committed when
     *        the operation completes without an
     *        unhandled exception
     *   -- Always executes under a flowed transaction.
     */
    [OperationBehavior(
      TransactionAutoComplete = true,
      TransactionScopeRequired = true
    )]
    [TransactionFlow(TransactionFlowOption.Mandatory)]
    public string TxWork(string message)
    {
      // Do some transactable work.
      Console.WriteLine("TxWork called with: " + message);
      // Display transaction information.

      TransactionInformation info = Transaction.Current.TransactionInformation;
      Console.WriteLine("The distributed tx ID: {0}.", info.DistributedIdentifier);
      Console.WriteLine("The tx status: {0}.", info.Status);
      return String.Format("Hello. This was object {0}.",myID.ToString()) ;
    }

    public void Dispose()
    {
      Console.WriteLine(
        "Service "
        + myID.ToString()
        + " is being recycled."
      );
    }
  }
}
Imports System.ServiceModel
Imports System.Transactions

Namespace Microsoft.WCF.Documentation
  <ServiceContract(Namespace:="http://microsoft.wcf.documentation", SessionMode:=SessionMode.Required)> _
  Public Interface IBehaviorService
    <OperationContract> _
    Function TxWork(ByVal message As String) As String
  End Interface

  ' Note: To use the TransactionIsolationLevel property, you 
  ' must add a reference to the System.Transactions.dll assembly.
'   The following service implementation:
'   *   -- Processes messages on one thread at a time
'   *   -- Creates one service object per session
'   *   -- Releases the service object when the transaction commits
'   
    <ServiceBehavior(ConcurrencyMode:=ConcurrencyMode.Single, InstanceContextMode:=InstanceContextMode.PerSession, _
                     ReleaseServiceInstanceOnTransactionComplete:=True)> _
    Public Class BehaviorService
        Implements IBehaviorService, IDisposable
        Private myID As Guid

        Public Sub New()
            myID = Guid.NewGuid()
            Console.WriteLine("Object " & myID.ToString() & " created.")
        End Sub

        '    
        '     * The following operation-level behaviors are specified:
        '     *   -- The executing transaction is committed when
        '     *        the operation completes without an 
        '     *        unhandled exception
        '     *   -- Always executes under a flowed transaction.
        '     
        <OperationBehavior(TransactionAutoComplete:=True, TransactionScopeRequired:=True), TransactionFlow(TransactionFlowOption.Mandatory)> _
        Public Function TxWork(ByVal message As String) As String Implements IBehaviorService.TxWork
            ' Do some transactable work.
            Console.WriteLine("TxWork called with: " & message)
            ' Display transaction information.

            Dim info As TransactionInformation = Transaction.Current.TransactionInformation
            Console.WriteLine("The distributed tx ID: {0}.", info.DistributedIdentifier)
            Console.WriteLine("The tx status: {0}.", info.Status)
            Return String.Format("Hello. This was object {0}.", myID.ToString())
        End Function

        Public Sub Dispose() Implements IDisposable.Dispose
            Console.WriteLine("Service " & myID.ToString() & " is being recycled.")
        End Sub
    End Class
End Namespace

다음 코드 예제가 제대로 실행되려면 기본 바인딩에서 트랜잭션 이동을 지원해야 합니다. 예를 들어, WSHttpBinding을 사용하여 트랜잭션 이동을 지원하려면 코드 또는 애플리케이션 구성 파일에서 TransactionFlow 속성을 true로 설정합니다. 다음 코드 예제에서는 앞에 나온 샘플에 대한 구성 파일을 보여 줍니다.

<configuration>
  <system.serviceModel>
    <services>
      <service  
        name="Microsoft.WCF.Documentation.BehaviorService" 
        behaviorConfiguration="metadataAndDebugEnabled"
      >
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/SampleService"/>
          </baseAddresses>
        </host>
        <!--
          Note:
            This example code uses the WSHttpBinding to support transactions using the 
            WS-AtomicTransactions (WS-AT) protocol. WSHttpBinding is configured to use the  
            protocol, but the protocol is not enabled on some computers. Use the xws_reg -wsat+ 
            command to enable the WS-AtomicTransactions protocol in the MSDTC service.          
          -->
        <endpoint 
           contract="Microsoft.WCF.Documentation.IBehaviorService"
           binding="wsHttpBinding"
           bindingConfiguration="wsHttpBindingWithTXFlow"
           address="http://localhost:8080/BehaviorService"
          />
        <endpoint 
           contract="Microsoft.WCF.Documentation.IBehaviorService"
           binding="netTcpBinding"
           bindingConfiguration="netTcpBindingWithTXFlow"
           address="net.tcp://localhost:8081/BehaviorService"
          />
        <endpoint
          address="mex"
          binding="mexHttpBinding"
          contract="IMetadataExchange"
        />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="metadataAndDebugEnabled">
          <serviceDebug
            includeExceptionDetailInFaults="true"
          />
          <serviceMetadata
            httpGetEnabled="true"
            httpGetUrl=""
          />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <!-- binding configuration - configures a WSHttpBinding to require transaction flow -->
    <bindings>
      <wsHttpBinding>
        <binding name="wsHttpBindingWithTXFlow" transactionFlow="true" />
      </wsHttpBinding>
      <netTcpBinding>
        <binding name="netTcpBindingWithTXFlow" transactionFlow="true" />
      </netTcpBinding>
    </bindings>
  </system.serviceModel>
</configuration>

설명

디버깅을 위해 예외 정보가 클라이언트로 이동할 수 있게 하려면 IncludeExceptionDetailInFaultstrue로 설정합니다. 이 속성에서는 요청-응답 또는 이중 메시징을 지원하는 바인딩이 필요합니다.

관리되는 모든 애플리케이션에서 처리 오류는 Exception 개체로 표시됩니다. SOAP 기반 애플리케이션에서 WCF 애플리케이션과 같은 서비스 작업을 구현 하는 메서드는 오류 정보를 SOAP 오류 메시지를 사용 하 여 통신 합니다. WCF 애플리케이션 두 가지 유형의 오류 시스템에서 실행 되므로 클라이언트로 전송 해야 하는 모든 관리 되는 예외 정보는 예외에서 SOAP 오류로 변환 되어야 합니다. 자세한 내용은 지정 및 계약 및 서비스에서 오류 처리합니다.

개발 과정에서 디버깅에 도움이 되도록 서비스에서 기타 예외도 클라이언트에 돌려보내도록 하는 경우가 있습니다. 이는 개발 전용 기능이므로 배포된 서비스에서는 사용할 수 없습니다.

디버깅 개발을 용이 하 게 설정 합니다 IncludeExceptionDetailInFaultstrue 코드 또는 애플리케이션 구성 파일을 사용 합니다.

이 설정을 사용하면 서비스는 더 안전한 예외 정보를 자동으로 호출자에게 반환합니다. 이 오류는 FaultException<TDetail> 형식의 ExceptionDetail 개체로 클라이언트에 나타납니다.

중요

설정 IncludeExceptionDetailInFaultstrue 내부 정보를 가져올 수 있도록 클라이언트는 서비스 메서드 예외;만 임시로 서비스 애플리케이션을 디버깅 하는 방법으로 권장 됩니다. 또한 이 방법으로 처리되지 않은 관리되는 예외를 반환하는 메서드의 WSDL에는 FaultException<TDetail> 형식의 ExceptionDetail에 대한 계약이 포함되지 않습니다. 디버깅 정보를 제대로 얻으려면 클라이언트는 알 수 없는 SOAP 오류의 가능성을 예상해야 합니다.

다음 코드 예제와 같이 애플리케이션 구성 파일 및 <serviceDebug> 요소를 사용하여 이 속성을 true 설정할 수도 있습니다.

<serviceBehaviors>
  <behavior name="metadataAndDebugEnabled">
    <serviceDebug
      includeExceptionDetailInFaults="true"
    />
    <serviceMetadata
      httpGetEnabled="true"
      httpGetUrl=""
    />
  </behavior>
</serviceBehaviors>

적용 대상