ServiceContractAttribute.SessionMode 속성

정의

세션이 허용되는지, 허용되지 않는지 또는 필요한지를 가져오거나 설정합니다.

public:
 property System::ServiceModel::SessionMode SessionMode { System::ServiceModel::SessionMode get(); void set(System::ServiceModel::SessionMode value); };
public System.ServiceModel.SessionMode SessionMode { get; set; }
member this.SessionMode : System.ServiceModel.SessionMode with get, set
Public Property SessionMode As SessionMode

속성 값

세션이 허용되는지, 허용되지 않는지 또는 필요한지를 나타내는 SessionMode입니다.

예외

값이 SessionMode 값 중 하나가 아닌 경우

예제

다음 서비스 계약을 사용하려면 구성된 바인딩이 서비스 구현과 SampleDuplexHello 상호 작용할 때 세션을 사용해야 합니다.

using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.Threading;

namespace Microsoft.WCF.Documentation
{
  [ServiceContract(
    Name = "SampleDuplexHello",
    Namespace = "http://microsoft.wcf.documentation",
    CallbackContract = typeof(IHelloCallbackContract),
    SessionMode = SessionMode.Required
  )]
  public interface IDuplexHello
  {
    [OperationContract(IsOneWay = true)]
    void Hello(string greeting);
  }

  public interface IHelloCallbackContract
  {
    [OperationContract(IsOneWay = true)]
    void Reply(string responseToGreeting);
  }

  [ServiceBehaviorAttribute(InstanceContextMode=InstanceContextMode.PerSession)]
  public class DuplexHello : IDuplexHello
  {

    public DuplexHello()
    {
      Console.WriteLine("Service object created: " + this.GetHashCode().ToString());
    }

    ~DuplexHello()
    {
      Console.WriteLine("Service object destroyed: " + this.GetHashCode().ToString());
    }

    public void Hello(string greeting)
    {
      Console.WriteLine("Caller sent: " + greeting);
      Console.WriteLine("Session ID: " + OperationContext.Current.SessionId);
      Console.WriteLine("Waiting two seconds before returning call.");
      // Put a slight delay to demonstrate asynchronous behavior on client.
      Thread.Sleep(2000);
      IHelloCallbackContract callerProxy
        = OperationContext.Current.GetCallbackChannel<IHelloCallbackContract>();
      string response = "Service object " + this.GetHashCode().ToString() + " received: " + greeting;
      Console.WriteLine("Sending back: " + response);
      callerProxy.Reply(response);
    }
  }
}


Imports System.Collections.Generic
Imports System.ServiceModel
Imports System.Threading

Namespace Microsoft.WCF.Documentation
    <ServiceContract(Name:="SampleDuplexHello", Namespace:="http://microsoft.wcf.documentation", _
                     CallbackContract:=GetType(IHelloCallbackContract), SessionMode:=SessionMode.Required)> _
    Public Interface IDuplexHello
        <OperationContract(IsOneWay:=True)> _
        Sub Hello(ByVal greeting As String)
    End Interface

  Public Interface IHelloCallbackContract
    <OperationContract(IsOneWay := True)> _
    Sub Reply(ByVal responseToGreeting As String)
  End Interface

  <ServiceBehaviorAttribute(InstanceContextMode:=InstanceContextMode.PerSession)> _
  Public Class DuplexHello
      Implements IDuplexHello

    Public Sub New()
      Console.WriteLine("Service object created: " & Me.GetHashCode().ToString())
    End Sub

    Protected Overrides Sub Finalize()
      Console.WriteLine("Service object destroyed: " & Me.GetHashCode().ToString())
    End Sub

    Public Sub Hello(ByVal greeting As String) Implements IDuplexHello.Hello
      Console.WriteLine("Caller sent: " & greeting)
      Console.WriteLine("Session ID: " & OperationContext.Current.SessionId)
      Console.WriteLine("Waiting two seconds before returning call.")
      ' Put a slight delay to demonstrate asynchronous behavior on client.
      Thread.Sleep(2000)
      Dim callerProxy As IHelloCallbackContract = OperationContext.Current.GetCallbackChannel(Of IHelloCallbackContract)()
            Dim response = "Service object " & Me.GetHashCode().ToString() & " received: " & greeting
      Console.WriteLine("Sending back: " & response)
      callerProxy.Reply(response)
    End Sub
  End Class
End Namespace

설명

사용 하 SessionMode 여는 엔드포인트 간의 세션을 지원 하는 바인딩을 요구 하는 속성입니다. 세션은 둘 이상의 엔드포인트 간에 교환되는 메시지 집합의 상관 관계를 지정하는 방법입니다. 서비스에서 채널 세션을 지원하는 경우 속성을 사용하여 InstanceContextMode 서비스 계약 구현 인스턴스와 채널 세션 간의 관계를 지정할 수 있습니다. 바인딩이 세션을 지원하지 않으면 예외가 throw됩니다.

예를 들어 속성이 SessionMode 로 설정 SessionMode.Required 되고 InstanceContextMode 속성이 로 PerSession설정된 경우 클라이언트는 동일한 연결을 사용하여 동일한 서비스 개체를 반복적으로 호출할 수 있습니다.

세션 및 서비스 인스턴스에 대한 자세한 내용은 세션세션 사용, 인스턴스화 및 동시성을 참조하세요.

참고

세션을 지원하는 채널은 특정 세션과 서비스 인스턴스의 기본 연결을 지원합니다. 그러나 다른 세션 구현은 세션 기반 인스턴스화 제어 외에도 다양한 기능을 지원합니다. WCF는 네 가지 유형의 세션 애플리케이션 동작을 제공 하는 데 사용할 수 있는 세션을 제공 합니다. 세션의 각 유형에 세션의 형식에 맞는 추가 동작을 제공 합니다.

  1. System.ServiceModel.Channels.SecurityBindingElement 통신의 양쪽 끝이 암호화 및/또는 디지털 서명 프로세스에 동의한 보안 세션을 지원합니다. 모든 메시지는 특정 보안 대화와 상관 관계가 있습니다. 자세한 내용은 서비스 보안을 참조하세요. 예를 들어 보안 System.ServiceModel.WSHttpBinding세션과 신뢰할 수 있는 세션 모두에 대한 지원을 포함하는 는 기본적으로 메시지를 암호화하고 디지털 서명하는 보안 세션만 사용합니다.

  2. System.ServiceModel.NetTcpBinding TCP/IP 연결에서 노출되는 세션을 지원하여 모든 메시지가 소켓 수준의 연결 세션과 상호 연결되도록 합니다.

  3. WS-ReliableMessaging 사양을 구현하는 는 System.ServiceModel.Channels.ReliableSessionBindingElement메시지가 순서대로 정확히 한 번 배달되는 신뢰할 수 있는 세션을 지원하므로 대화 중에 메시지가 여러 노드를 이동할 때도 안심할 수 있습니다. 자세한 내용은 신뢰할 수 있는 세션을 참조하세요.

  4. System.ServiceModel.NetMsmqBinding MSMQ 데이터그램 세션을 제공합니다. 자세한 내용은 WCF의 큐를 참조하세요.

속성을 설정 SessionMode 해도 계약에 필요한 세션 유형은 지정되지 않으며, 필요한 세션 유형만 지정해야 합니다.

적용 대상