Language

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 。 既定値は 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);
    }
  }
}

注釈

双方向 (または双方向) メッセージ交換で必要な反対のコントラクトを表すインターフェイスを CallbackContract プロパティで指定します。 これにより、クライアント アプリケーションは、サーバー側サービス アプリケーションがクライアント アクティビティとは別に送信できる受信操作呼び出しをリッスンできます。 一方向の操作を持つコールバック コントラクトは、クライアントが処理できるサービスからの呼び出しを表します。

Note

コールバック コントラクトでは、 ServiceContractAttribute 属性は無視されます。 コールバック オブジェクトのランタイム動作を構成するには、 System.ServiceModel.CallbackBehaviorAttributeを使用します。

適用対象