OperationBehaviorAttribute 클래스

정의

서비스 메서드의 로컬 실행 동작을 지정합니다.

public ref class OperationBehaviorAttribute sealed : Attribute, System::ServiceModel::Description::IOperationBehavior
[System.AttributeUsage(System.AttributeTargets.Method)]
public sealed class OperationBehaviorAttribute : Attribute, System.ServiceModel.Description.IOperationBehavior
[<System.AttributeUsage(System.AttributeTargets.Method)>]
type OperationBehaviorAttribute = class
    inherit Attribute
    interface IOperationBehavior
Public NotInheritable Class OperationBehaviorAttribute
Inherits Attribute
Implements IOperationBehavior
상속
OperationBehaviorAttribute
특성
구현

예제

다음 코드 예제에서는 필수 분산 트랜잭션 내에서 실행되는 작업을 보여 줍니다. TransactionScopeRequired 속성은 메서드가 호출자의 트랜잭션에서 실행됨을 나타내며, TransactionAutoComplete 속성은 처리되지 않은 예외가 발생하지 않을 경우 트랜잭션이 자동으로 커밋됨을 나타냅니다. 처리되지 않은 예외가 발생하면 트랜잭션은 중단됩니다.

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:
     *   -- Always executes under a transaction scope.
     *   -- The transaction scope is completed when the operation terminates
     *       without an unhandled exception.
     */
    [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:
        '     *   -- Always executes under a transaction scope.
        '     *   -- The transaction scope is completed when the operation terminates 
        '     *       without an unhandled exception.
        '     
        <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

설명

작업 실행 시 어떤 작업별 실행 동작이 있는지 나타내려면 OperationBehaviorAttribute 특성을 사용합니다. 서비스 수준의 실행 동작을 지정하려면 ServiceBehaviorAttribute 특성을 사용합니다.

참고

또한 OperationBehaviorAttribute를 사용하여 이중 클라이언트 애플리케이션에서 콜백 계약 작업을 구성할 수도 있습니다. 콜백 작업에 사용하는 경우 ReleaseInstanceMode 속성이 None이어야 하며, 그렇지 않으면 런타임에 InvalidOperationException 예외가 throw됩니다.

OperationBehaviorAttribute 특성은 개발자가 직접 구현 해야 하는 일반적인 기능을 사용 하는 Windows Communication Foundation (WCF) 프로그래밍 모델 기능입니다.

  • AutoDisposeParameters 속성은 작업 완료 시 작업에 전달된 매개 변수 개체의 삭제 여부를 제어합니다.

  • TransactionAutoComplete 속성은 처리되지 않은 예외가 발생하지 않는 경우 메서드가 실행되는 트랜잭션의 자동 커밋 여부를 지정합니다.

  • TransactionScopeRequired 속성은 트랜잭션 내에서 메서드를 실행해야 하는지 여부를 지정합니다.

  • Impersonation 속성은 서비스 작업이 호출자의 ID를 가장할 수 있는지, 가장해야 하는지 또는 가장할 수 없는지를 지정합니다.

  • ReleaseInstanceMode 속성은 메서드 호출 프로세스 중에 서비스 개체를 재활용하는 시점을 지정합니다.

생성자

OperationBehaviorAttribute()

OperationBehaviorAttribute 클래스의 새 인스턴스를 초기화합니다.

속성

AutoDisposeParameters

매개 변수가 자동으로 삭제되는지 여부를 나타내는 값을 가져오거나 설정합니다.

Impersonation

작업에서 지원하는 호출자 가장 수준을 나타내는 값을 가져오거나 설정합니다.

ReleaseInstanceMode

작업 호출 과정에서 서비스 개체를 재활용할 시점을 나타내는 값을 가져오거나 설정합니다.

TransactionAutoComplete

처리되지 않은 예외가 발생하지 않을 때 현재 트랜잭션 범위를 자동으로 완료할지 여부를 나타내는 값을 가져오거나 설정합니다.

TransactionScopeRequired

메서드 실행에 트랜잭션 범위가 필요한지 여부를 나타내는 값을 가져오거나 설정합니다.

TypeId

파생 클래스에서 구현된 경우 이 Attribute에 대한 고유 식별자를 가져옵니다.

(다음에서 상속됨 Attribute)

메서드

Equals(Object)

이 인스턴스가 지정된 개체와 같은지를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
GetHashCode()

이 인스턴스의 해시 코드를 반환합니다.

(다음에서 상속됨 Attribute)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
IsDefaultAttribute()

파생 클래스에서 재정의된 경우 이 인스턴스 값이 파생 클래스에 대한 기본값인지 여부를 표시합니다.

(다음에서 상속됨 Attribute)
Match(Object)

파생 클래스에서 재정의된 경우 이 인스턴스가 지정된 개체와 같은지 여부를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

이름 집합을 해당하는 디스패치 식별자 집합에 매핑합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

인터페이스의 형식 정보를 가져오는 데 사용할 수 있는 개체의 형식 정보를 검색합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

개체에서 제공하는 형식 정보 인터페이스의 수를 검색합니다(0 또는 1).

(다음에서 상속됨 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

개체에서 노출하는 메서드와 속성에 대한 액세스를 제공합니다.

(다음에서 상속됨 Attribute)
IOperationBehavior.AddBindingParameters(OperationDescription, BindingParameterCollection)

AddBindingParameters(OperationDescription, BindingParameterCollection) 메서드를 구현합니다.

IOperationBehavior.ApplyClientBehavior(OperationDescription, ClientOperation)

클라이언트 작업 동작을 구현합니다.

IOperationBehavior.ApplyDispatchBehavior(OperationDescription, DispatchOperation)

서비스 작업 동작을 구현합니다.

IOperationBehavior.Validate(OperationDescription)

유효성 검사 동작을 구현합니다.

적용 대상