ServiceContractAttribute.CallbackContract ServiceContractAttribute.CallbackContract ServiceContractAttribute.CallbackContract ServiceContractAttribute.CallbackContract Property

Définition

Obtient ou définit le type de contrat de rappel lorsque le contrat est un contrat duplex.Gets or sets the type of callback contract when the contract is a duplex contract.

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

Valeur de propriété

Type qui indique le contrat de rappel.A Type that indicates the callback contract. La valeur par défaut est null.The default is null.

Exemples

L'exemple de code suivant présente un service qui spécifie un contrat de rappel. Il indique qu'un service de type IDuplexHello doit avoir un correspondant qui implémente un service de type IHelloCallbackContract.The following code example shows a service that specifies a callback contract, which indicates that a service of type IDuplexHello must have a correspondent that implements a service of type IHelloCallbackContract. De plus, IHelloCallbackContract implémente une méthode de rappel unidirectionnelle, ce qui permet au service d'appeler le client sans attendre une réponse pour prendre en charge un client distribué et piloté par des événements.In addition, IHelloCallbackContract implements a one-way callback method, enabling the service to call the client without waiting for a reply to support a distributed, event-driven client.

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

Remarques

Spécifiez une interface dans la propriété CallbackContract qui représente le contrat opposé requis dans un échange de messages bidirectionnel (ou duplex).Specify an interface in the CallbackContract property that represents the required opposite contract in a two-way (or duplex) message exchange. Cela permet aux applications clientes d'écouter les appels d'opération entrants que l'application de service côté serveur peut envoyer indépendamment des activités clientes.This enables client applications to listen for inbound operation calls that the server-side service application can send independently of client activity. Les contrats de rappel qui ont des opérations unidirectionnelles représentent les appels du service que le client peut gérer.Callback contracts that have one-way operations represent calls from the service that the client can handle.

Notes

L'attribut ServiceContractAttribute est ignoré sur les contrats de rappel.The ServiceContractAttribute attribute is ignored on callback contracts. Pour configurer le comportement d'exécution des objets de rappel, utilisez la System.ServiceModel.CallbackBehaviorAttribute.To configure runtime behavior of callback objects, use the System.ServiceModel.CallbackBehaviorAttribute.

S’applique à