Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
 CallbackContract Property
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
ServiceContractAttribute..::.CallbackContract Property

Updated: November 2007

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)

Visual Basic (Declaration)
Public Property CallbackContract As Type
Visual Basic (Usage)
Dim instance As ServiceContractAttribute
Dim value As Type

value = instance.CallbackContract

instance.CallbackContract = value
C#
public Type CallbackContract { get; set; }
Visual C++
public:
property Type^ CallbackContract {
    Type^ get ();
    void set (Type^ value);
}
J#
/** @property */
public Type get_CallbackContract()
/** @property */
public  void set_CallbackContract(Type value)
JScript
public function get CallbackContract () : Type
public function set CallbackContract (value : Type)

Property Value

Type: System..::.Type

A Type that indicates the callback contract. The default is nullNothingnullptra null reference (Nothing in Visual Basic).

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.

Note:

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.

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

Windows Vista, Windows XP SP2, 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
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker