added samples
[windows-sources.git] / sdk / samples / WCFSamples / TechnologySamples / Basic / Contract / Service / Duplex / VB / client / client.vb
blob3a4a1f768e7161f0422db40731cc0b8fd7e1477c
1 ' Copyright (c) Microsoft Corporation. All Rights Reserved.
3 Imports System
4 Imports System.ServiceModel
6 Namespace Microsoft.ServiceModel.Samples
8 ' The service contract is defined in generatedClient.vb, generated from the service by the svcutil tool.
10 ' Define class which implements callback interface of duplex contract
11 Public Class CallbackHandler
12 Implements ICalculatorDuplexCallback
14 Public Sub Result(ByVal result As Double) Implements ICalculatorDuplexCallback.Result
16 Console.WriteLine("Result({0})", result)
18 End Sub
20 Public Sub Equation(ByVal eqn As String) Implements ICalculatorDuplexCallback.Equation
22 Console.WriteLine("Equation({0})", eqn)
24 End Sub
26 End Class
28 Class Client
30 Public Shared Sub Main()
32 ' Construct InstanceContext to handle messages on callback interface
33 Dim instanceContext As New InstanceContext(New CallbackHandler())
35 ' Create a client
36 Dim client As New CalculatorDuplexClient(instanceContext)
37 Console.WriteLine("Press <ENTER> to terminate client once the output is displayed.")
38 Console.WriteLine()
40 ' Call the AddTo service operation.
41 Dim value As Double = 100
42 client.AddTo(value)
44 ' Call the SubtractFrom service operation.
45 value = 50
46 client.SubtractFrom(value)
48 ' Call the MultiplyBy service operation.
49 value = 17.65
50 client.MultiplyBy(value)
52 ' Call the DivideBy service operation.
53 value = 2
54 client.DivideBy(value)
56 ' Complete equation
57 client.Clear()
59 Console.ReadLine()
61 'Closing the client gracefully closes the connection and cleans up resources
62 client.Close()
64 End Sub
66 End Class
68 End Namespace