Skip to main content

Indigo Duplex Bindings

Posted by arungupta on May 16, 2005 at 1:26 PM PDT

In part
of the series, I gave a short tutorial on Indigo
bindings. In this entry, I'll describe Indigo Duplex bindings and related code

Indigo Duplex Binding enables bi-directional communication between a service
and client. The steps
in Indigo documentation
are scattered unless I look at the Duplex
Contract sample
. In this entry I'm listing all the steps and tried
explaining my understanding at each step with certain questions I'm still trying
to answer.

In a single direction communication, client can invoke a set of operations on
a service and this interface is referred as "primary" interface in
Duplex binding. The set of operations that service can invoke on client is
called as "callback" interface. To enable bi-directional
communication, here is what I need to do on the service side:

  1. Link the "primary" and "callback" interface by setting
    CallbackContract property in the "primary" interface to the type of
    the "callback" interface.
  2. Get the CallbackChannel from OperationContext
    specifying the "callback" interface

Here is the service endpoint interface showing the linking using CallbackContract
in line (01):

(01) [ServiceContract(CallbackContract=typeof(ICalculatorCallback)]
(02) public interface ICalculator {
(03)   [OperationContract]
(04)   double add(double n1, double n2);
(05) }
(07) public interface ICalculatorCallback {
(08)   [OperationContract]
(09)   void display(string line);
(10) }

Line (02) to (05) is the "primary" interface and line (07) to (10)
is the "callback" interface. Here is the service endpoint

(01) public class CalculatorService : ICalculator {
(02)   CalculatorCallback callback = null;
(03)   public CalculatorService() {
(04)     callback = OperationContext.Current.GetCallbackChannel();
(05)   }
(07)   public double add(double n1, double n2) {
(08)     callback.display(    
Related Topics >>