The Client

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

graphics/f18dp05.jpg

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 method
 Private 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 startup
 Private 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

graphics/f18dp06.jpg

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

graphics/f18dp07.jpg

Listing 18-24 Submitting a new task
 Private 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.




Microsoft. NET Distributed Applications(c) Integrating XML Web Services and. NET Remoting
MicrosoftВ® .NET Distributed Applications: Integrating XML Web Services and .NET Remoting (Pro-Developer)
ISBN: 0735619336
EAN: 2147483647
Year: 2005
Pages: 174

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net