ServiceContractAttribute.CallbackContract 속성

정의

계약이 이중 계약인 경우 콜백 계약의 형식을 가져오거나 설정합니다.

public:
 property Type ^ CallbackContract { Type ^ get(); void set(Type ^ value); };
public Type CallbackContract { get; set; }
member this.CallbackContract : Type with get, set
Public Property CallbackContract As Type

속성 값

Type

콜백 계약을 나타내는 Type입니다. 기본값은 null입니다.

예제

다음 코드 예제에서는 형식의 서비스에 형식 IDuplexHello 의 서비스를 구현하는 특파원이 있어야 하므로 콜백 계약을 지정하는 서비스를 IHelloCallbackContract보여 줍니다. 또한 IHelloCallbackContract 단방향 콜백 메서드를 구현하여 서비스가 분산 이벤트 기반 클라이언트를 지원하기 위해 회신을 기다리지 않고 클라이언트를 호출할 수 있도록 합니다.

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);
  }

  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

  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 = 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

설명

양방향(또는 이중) 메시지 교환에서 CallbackContract 필요한 반대 계약을 나타내는 인터페이스를 속성에 지정합니다. 이렇게 하면 클라이언트 애플리케이션에서는 서버측 서비스 애플리케이션이 클라이언트 동작과 별도로 보낼 수 있는 인바운드 작업 호출을 수신 대기할 수 있습니다. 단방향 작업이 있는 콜백 계약은 클라이언트가 처리할 수 있는 서비스의 호출을 나타냅니다.

참고

ServiceContractAttribute 콜백 계약에서는 특성이 무시됩니다. 콜백 개체의 런타임 동작을 구성하려면 .System.ServiceModel.CallbackBehaviorAttribute

적용 대상