The client code is a straightforward Windows Forms application that enables the user to upload new tasks and view the progress of current tasks. When the application first starts, the user is prompted to log in (as shown in Figure 18-5). Figure 18-5. The Login window
The client code includes a private Login function that shows the login form until the client cancels the attempt or the login succeeds, as shown in Listing 18-22. Listing 18-22 The client Login methodPrivate Proxy As New localhost.RenderService() Private Function Login() Dim frmLogin As New Login() Do While frmLogin.ShowDialog() = DialogResult.OK ' Create the SOAP header with the user name and password. Dim Ticket As New localhost.TicketHeader() Ticket.UserName = frmLogin.UserName Ticket.Password = frmLogin.Password ' Assign the header to the proxy instance. Proxy.TicketHeaderValue = Ticket ' Try to log in. If Proxy.Login() Then Return True Loop ' Login was cancelled. Return False End Function If the user can be successfully authenticated by the XML Web service, the application continues by retrieving and displaying the user's list of tasks (as shown in Listing 18-23). Figure 18-6 shows the client form in action. Listing 18-23 Logging in and retrieving tasks at startupPrivate Sub Client_Load(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles MyBase.Load ' Try to authenticate the user. If Login() Then Display("Successfully logged in.") SetUpForm() Else Application.Exit() End If End Sub Private Sub SetUpForm() Dim Tasks As DataSet Tasks = Proxy.GetTasks(False) Display("List of " & Tasks.Tables(0).Rows.Count.ToString() & _ " current task(s) retrieved.") gridTasks.DataSource = Tasks.Tables(0) End Sub Figure 18-6. The client interface
A custom Display method is used to quickly add text to a read-only text box display: Private Sub Display(ByVal message As String) txtStatus.Text &= message txtStatus.Text &= System.Environment.NewLine End Sub The remainder of the interface is quite predictable. When the form closes, the Logout Web method is called automatically. When the Submit New button is clicked, a common Open dialog box is used to select the file. When the user selects a file, it's transferred to the server using the SubmitTask Web method (see Listing 18-24). Figure 18-7 shows the results. Figure 18-7. Submitting a task
Listing 18-24 Submitting a new taskPrivate Sub cmdSubmit_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles cmdSubmit.Click If dlgOpen.ShowDialog() = DialogResult.OK Then Dim fs As New FileStream(dlgOpen.FileName, FileMode.Open) Dim Buffer As Byte() ReDim Buffer(fs.Length) fs.Read(Buffer, 0, fs.Length) fs.Close() Dim Guid As Guid = Proxy.SubmitTask(Buffer, dlgOpen.FileName) Display("Task submitted. Confirmation: " & Guid.ToString()) End If End Sub Note One interesting technique used in the client interface is a horizontal splitter bar, which enables the user to decide how much of the window is used for the text information display and how much for the list of current tasks. The split display is implemented using separate docked panels. To examine it in detail, download the SuperCompute case study. |