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

Universal Windows Platform
Available since 8
.NET Framework
Available since 3.0
Portable Class Library
Supported in: portable .NET platforms
Available since 3.0
Windows Phone Silverlight
Available since 7.0
Return to top