9.9.1 Refresh the Web Service Reference for Our Window-Based Client Project
In order to call the InsertFaculty() operation in our Web service project, WebService Faculty, we need to refresh the Web reference in our Window-based client project to use the updated Web service project. Perform the following operations to refresh the Web service reference:
1) Build and deploy our Web Service application, WebAppFaculty, to make it available.
2) Open our Window-based client project, WinClientFaculty _ Insert, and expand
the Web Service References node.
3) Right-click on our Web service, WebServiceFaculty, and choose the Delete item to remove this old Web reference.
4) Right-click on our Window-based client project, WinClientFaculty _ Insert, and select the New > Web Service Client item to open the New Web Service Client wizard.
5) In the opened wizard, click on the Browse button next to the Project field and expand our Web application, WebAppFaculty. Then choose our Web service, WebServiceFaculty, by clicking on it, and click on the OK button.
6) Click on the Finish button to complete the Web service reference refresh process.
Now that we have refreshed or updated the Web service reference for our Window-based client project WinClientFaculty _ Insert, next let’s develop the code in our client project to call the Web service operation InsertFaculty() to perform faculty data insertion.
9.9.2 Develop the Code to Call Our Web Service Project
Open the Window-based client project WinClientFaculty _ Insert and double-click on our main class, FacultyFrame.java, to open it. Click on the Design button to open the graphic user interface. In this client project, we want to use the Insert button in this form as a trigger to start the faculty data insertion action. Therefore, double-click on the Insert button to open its event method, InsertButtonActionPerformed(), and enter the code shown in Figure 9.45 into this method.
Let’s have a closer look at this piece of code to see how it works.
A. Some local objects are first declared, which include a File object, imgFile, which is used to hold the selected image file, and a new ArrayList instance, al, which is used to pick up and reserve the input new faculty data array.
B. A Java File Chooser instance, imgChooser, is generated, and it provides a file interface GUI to allow users to select a desired faculty image to be inserted into our database later.
C. The current directory, which is the folder of our current project, is selected, and this loca-tion will work as a default folder to store all selected faculty image files later.
D. The system method, showOpenDialog(), is executed to display the Chooser GUI to enable users to browse and select a desired faculty image to be inserted into our database later.
E. By checking one property, APPROVE _ OPTION, one can confirm whether the GUI oper-ation is successful. If it is opened and an image has been selected, a true is returned. Then the selected image can be retrieved by calling a method, getSelectedFile().
F. These two code lines are used to display the path and directory for the selected faculty image, and they are used for debugging purposes.
G. The clear() method is executed to make sure that the ArrayList instance is clean and empty before a new faculty record can be assigned to it.