This documentation is archived and is not being maintained.

ServiceContractAttribute.CallbackContract Property

Gets or sets the type of callback contract when the contract is a duplex contract.

Namespace:  System.ServiceModel
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public Type CallbackContract { get; set; }

Property Value

Type: System.Type
A Type that indicates the callback contract. The default is null.

Specify an interface in the CallbackContract property that represents the required opposite contract in a two-way (or duplex) message exchange. This enables client applications to listen for inbound operation calls that the server-side service application can send independently of client activity. Callback contracts that have one-way operations represent calls from the service that the client can handle.


The ServiceContractAttribute attribute is ignored on callback contracts. To configure runtime behavior of callback objects, use the System.ServiceModel.CallbackBehaviorAttribute.

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. 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
    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());

      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.
      IHelloCallbackContract callerProxy
        = OperationContext.Current.GetCallbackChannel<IHelloCallbackContract>();
      string response = "Service object " + this.GetHashCode().ToString() + " received: " + greeting;
      Console.WriteLine("Sending back: " + response);

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0