2 // Copyright (c) Microsoft Corporation. All Rights Reserved.
5 using System
.ServiceModel
;
7 namespace Microsoft
.ServiceModel
.Samples
9 //The service contract is defined in generatedClient.cs, generated from the service by the svcutil tool.
11 // Define class which implements callback interface of duplex contract
12 public class CallbackHandler
: ICalculatorDuplexCallback
14 public void Result(double result
)
16 Console
.WriteLine("Result({0})", result
);
19 public void Equation(string eqn
)
21 Console
.WriteLine("Equation({0})", eqn
);
25 //Client implementation code.
32 // Construct InstanceContext to handle messages on callback interface
33 InstanceContext site
= new InstanceContext(new CallbackHandler());
35 // Create a client with given client endpoint configuration
36 CalculatorDuplexClient client
= new CalculatorDuplexClient(site
);
38 Console
.WriteLine("Press <ENTER> to terminate client once the output is displayed.");
41 // Call the AddTo service operation.
42 double value = 100.00D
;
45 // Call the SubtractFrom service operation.
47 client
.SubtractFrom(value);
49 // Call the MultiplyBy service operation.
51 client
.MultiplyBy(value);
53 // Call the DivideBy service operation.
55 client
.DivideBy(value);
62 //Closing the client gracefully closes the connection and cleans up resources