Public Class Form1

    Private ServiceInstance As New localhost.PostalWebService()

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Attach an event handler
        ' for the async call.
        AddHandler ServiceInstance.GetPackageInfoCompleted, AddressOf GetPackageInfoCompleted
    End Sub


    Private Sub cmdGetInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGetInfo.Click
        Me.Cursor = Cursors.WaitCursor

        Dim PackageInfo As New localhost.ClientPackageInfo()
        PackageInfo = ServiceInstance.GetPackageInfo("221")
        MessageBox.Show("Received the delivery date: " & PackageInfo.DeliveryDate, "Web Service Info!")

        Me.Cursor = Me.DefaultCursor
    End Sub

    Private Sub cmdGetAsync_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGetAsync.Click
        ' Disable the button so that only one asynchronous
        ' call will be permitted at a time.
        cmdGetAsync.Enabled = False

        ' Start the asynchronous call.
        ' This method does not block your code.
        ServiceInstance.GetPackageInfoAsync("Call001", "Call001")

        ' Allow cancellation.
        cmdCancelAsync.Enabled = True
    End Sub

    Private Sub GetPackageInfoCompleted(ByVal sender As Object, ByVal e As localhost.GetPackageInfoCompletedEventArgs)
        If Not e.Cancelled Then
            MessageBox.Show("Received the delivery date: " & e.Result.DeliveryDate)
        End If
        cmdGetAsync.Enabled = True
    End Sub

    Private Sub cmdCancelAsync_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancelAsync.Click
        ServiceInstance.CancelAsync("Call001")
        cmdCancelAsync.Enabled = False
    End Sub
End Class
