ServiceBehaviorAttribute 클래스

정의

서비스 계약 구현의 내부 실행 동작을 지정합니다.

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

예제

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

  • 트랜잭션이 완료되면 서비스 개체가 재활용됩니다.

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

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

또한 작업 수준에서 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>

설명

서비스 전체 실행 동작을 지정하려면 ServiceBehaviorAttribute 특성을 서비스 구현에 적용합니다. 메서드 수준에서 실행 동작을 지정하려면 OperationBehaviorAttribute 특성을 사용합니다. 이 특성은 서비스 구현에만 적용할 수 있습니다. 작업 예제에 대 한 참조를 서비스: 동작 샘플합니다.

ServiceBehaviorAttribute 속성은 개발자가 구현 해야 하는 일반적인 기능을 사용 하는 Windows Communication Foundation (WCF) 프로그래밍 모델 기능입니다. 속성 및 기타 동작에 대 한 자세한 내용은 참조 하세요. 서비스 런타임 동작 지정합니다. 기본 런타임 속성에 대 한 자세한 내용은 참조는 다음 속성 집합의 일부 Extending ServiceHost 및 서비스 모델 계층합니다.

  • AddressFilterMode 속성은 디스패처 시스템이 요청을 처리하는 엔드포인트를 찾을 때 사용하는 필터의 형식을 지정합니다.

  • AutomaticSessionShutdown 속성은 채널이 닫히고 서비스가 나머지 메시지의 처리를 마쳤을 때 자동으로 세션을 닫습니다.

  • ConcurrencyMode 속성은 내부 스레딩 모델을 제어하여 재진입 콜백 개체나 다중 스레드 서비스의 지원을 가능하게 합니다.

  • ConfigurationName 속성은 구성 파일에서 name 요소의 <service> 특성에 사용할 이름을 선언하는 데 사용됩니다.

  • IgnoreExtensionDataObject 속성을 사용하면 런타임은 메시지 처리에 필요 없는 추가 serialization 정보를 무시할 수 있습니다.

  • IncludeExceptionDetailInFaults 속성은 서비스에서 처리되지 않은 예외가 SOAP 오류로 반환되는지 여부를 지정합니다. 이 속성은 디버깅 용도로만 사용할 수 있습니다.

  • InstanceContextMode 속성은 클라이언트와의 교환 과정에서 서비스 및 해당 서비스 개체를 재활용할 것인지 여부 및 그 시기를 지정합니다.

  • MaxItemsInObjectGraph 속성은 개체 그래프에서 serialize되는 항목의 수를 제한합니다.

  • NameNamespace 속성은 서비스 요소의 WSDL 식에 사용되는 이름과 네임스페이스를 제어합니다.

  • ReleaseServiceInstanceOnTransactionComplete 속성은 트랜잭션이 완료되었을 때 서비스 개체가 재활용되는지 여부를 지정합니다.

  • TransactionAutoCompleteOnSessionClose 속성에서는 세션을 닫을 때 처리되지 않은 트랜잭션을 완료할 것인지 여부를 지정합니다.

  • TransactionIsolationLevel 속성은 계약이 지원하는 트랜잭션 격리 수준을 지정합니다.

  • TransactionTimeout 속성은 트랜잭션 완료가 이루어지지 않으면 중단되는 기간을 지정합니다.

  • UseSynchronizationContext 속성은 인바운드 메서드 호출을 사용자 인터페이스 스레드와 자동으로 동기화하는지 여부를 나타냅니다.

  • ValidateMustUnderstand 속성은 MustUnderstand로 표시된 SOAP 헤더가 실제로 인식되었음을 확인해야 하는지 여부를 시스템에 알려 줍니다.

IncludeExceptionDetailInFaults 속성은 애플리케이션 구성 파일을 사용하여 설정할 수도 있습니다. 자세한 내용은 IncludeExceptionDetailInFaults를 참조하십시오.

생성자

ServiceBehaviorAttribute()

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

속성

AddressFilterMode

디스패처가 들어오는 메시지를 올바른 엔드포인트로 라우팅하는 데 사용하는 AddressFilterMode를 가져오거나 설정합니다.

AutomaticSessionShutdown

클라이언트가 출력 세션을 닫을 때 세션을 자동으로 닫을지 여부를 지정합니다.

ConcurrencyMode

서비스가 하나의 스레드, 여러 개의 스레드 또는 재진입 호출을 지원할지 여부를 가져오거나 설정합니다.

ConfigurationName

애플리케이션 구성 파일에서 서비스 요소를 찾는 데 사용되는 값을 가져오거나 설정합니다.

EnsureOrderedDispatch

서비스에서 주문한 디스패치를 확인하는지 여부를 나타내는 값을 가져오거나 설정합니다.

IgnoreExtensionDataObject

네트워크에서 알 수 없는 serialization 데이터를 보낼지 여부를 지정하는 값을 가져오거나 설정합니다.

IncludeExceptionDetailInFaults

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

InstanceContextMode

새 서비스 개체 생성 시점을 나타내는 값을 가져오거나 설정합니다.

MaxItemsInObjectGraph

serialize된 개체에 허용되는 최대 항목 수를 가져오거나 설정합니다.

Name

WSDL(웹 서비스 기술 언어)에서 서비스 요소의 이름 특성 값을 가져오거나 설정합니다.

Namespace

WSDL(웹 서비스 기술 언어)에서 서비스의 대상 네임스페이스 값을 가져오거나 설정합니다.

ReleaseServiceInstanceOnTransactionComplete

현재 트랜잭션이 완료되면 서비스 개체를 해제하는지 여부를 지정하는 값을 가져오거나 설정합니다.

TransactionAutoCompleteOnSessionClose

현재 세션이 오류 없이 닫힐 때 보류 중인 트랜잭션이 완료되는지 여부를 지정하는 값을 가져오거나 설정합니다.

TransactionIsolationLevel

서비스 내부에서 만들어지는 새 트랜잭션 및 클라이언트로부터 들어오는 트랜잭션의 트랜잭션 격리 수준을 지정합니다.

TransactionTimeout

트랜잭션을 완료해야 하는 기간을 가져오거나 설정합니다.

TypeId

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

(다음에서 상속됨 Attribute)
UseSynchronizationContext

현재 동기화 컨텍스트를 사용하여 실행 스레드를 선택할지 여부를 지정하는 값을 가져오거나 설정합니다.

ValidateMustUnderstand

SOAP MustUnderstand 헤더 처리를 시스템에서 수행하는지 아니면 애플리케이션에서 수행하는지를 지정하는 값을 가져오거나 설정합니다.

메서드

Equals(Object)

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

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

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

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

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

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

서비스를 구현하고 서비스의 단일 인스턴스로 사용되는 개체를 검색하며, 단일 인스턴스가 없는 경우 null입니다.

IsDefaultAttribute()

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

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

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

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

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

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

서비스를 구현하고 서비스의 단일 인스턴스로 사용되는 개체를 지정합니다.

ShouldSerializeConfigurationName()

ConfigurationName 속성이 기본값에서 변경되었으며 이를 serialize해야 하는지 여부를 나타내는 값을 반환합니다.

ShouldSerializeReleaseServiceInstanceOnTransactionComplete()

ReleaseServiceInstanceOnTransactionComplete 속성이 기본값에서 변경되었으며 이를 serialize해야 하는지 여부를 나타내는 값을 반환합니다.

ShouldSerializeTransactionAutoCompleteOnSessionClose()

TransactionAutoCompleteOnSessionClose 속성이 기본값에서 변경되었으며 이를 serialize해야 하는지 여부를 나타내는 값을 반환합니다.

ShouldSerializeTransactionIsolationLevel()

TransactionIsolationLevel 속성이 기본값에서 변경되었으며 이를 serialize해야 하는지 여부를 나타내는 값을 반환합니다.

ShouldSerializeTransactionTimeout()

TransactionTimeout 속성이 기본값에서 변경되었으며 이를 serialize해야 하는지 여부를 나타내는 값을 반환합니다.

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)
IServiceBehavior.AddBindingParameters(ServiceDescription, ServiceHostBase, Collection<ServiceEndpoint>, BindingParameterCollection)

사용자 지정 데이터 개체를 동작 속성을 지원하는 바인딩에 전달합니다.

IServiceBehavior.ApplyDispatchBehavior(ServiceDescription, ServiceHostBase)

동작 속성을 지원하도록 서비스 런타임을 사용자 지정합니다.

IServiceBehavior.Validate(ServiceDescription, ServiceHostBase)

서비스 설명 및 서비스 호스트가 동작을 지원할 수 있음을 확인합니다.

적용 대상

추가 정보