Visual Basic.NET Comprehensive Concepts and Techniques Chapter 12 Creating Console Applications, Understanding XML, and Creating Web Services
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 2 Objectives Start a new Console application Use parameters in a Console application Write code to create a comma-delimited text file Write code to create a tab-delimited text file Write code to create an XML file
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 3 Objectives Start a new ASP.NET Web service application Understand the structure of XML files Write code to read an XML file Use a Web service in code Debug Console applications and Web services
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 4
5 Starting Visual Basic.NET and Adding a New Public Procedure to a Module Insert the Data Disk in drive A. Start Visual Basic.NET. When the Start Page appears, click the Open Project button on the Start Page If necessary, click the Look in box arrow and then click 3½ Floppy (A:). Double-click the Chapter12 folder Double-click the Compensation Review folder. If necessary, click the Compensation Review solution file (Compensation Review.sln) Click the Open button. When the Compensation Review project appears in the Solution Explorer window, double- click the UpdateCompensation.vb module
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 6 Starting Visual Basic.NET and Adding a New Public Procedure to a Module Type lines 28 through 42, as shown below:
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 7 Building, Saving, and Documenting the Class Library Right-click the Compensation Review project in the Solution Explorer window. When the shortcut menu appears, click the Build command Click the UpdateCompensation.vb tab in the main work area. Use the Print command on the File menu to print a record of the code for the UpdateCompensation.vb module
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 8 Starting a New Console Application Project Right-click the Compensation Review solution in the Solution Explorer window. When the shortcut menu appears, click the Add command. When the Add submenu appears, click the New Project command When the Add New Project dialog box appears, click the Console Application icon in the Templates area. Select the text in the Name box. Type CompensationUpdateProcessing in the Name box Click the OK button
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 9 Starting a New Console Application Project Right-click the References folder in the CompensationUpdateProcessing project in the Solution Explorer window. When the shortcut menu appears, use the Add Reference command to add a reference to the Compensation Review.dll component located in the A:\Chapter12\Compensation Review\Compensation Review\bin folder Right-click the Module1.vb module in the Solution Explorer window. When the shortcut menu appears, click the Rename command. Type CompensationUpdateProcessing.vb as the new module name
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 10 Entering Initial Console Application Code Enter lines 1 through 4, as shown below:
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 11 Entering Code to Validate Command-Line Arguments Enter lines 7 through 10, as shown below:
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 12 Entering Code to Determine the Type of File to Create Type lines 11 through 20, as shown below:
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 13 Creating and Opening a Text File Type lines 23 through 40, as shown below:
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 14 Writing to a Text File Type lines 37 through 53, as shown below:
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 15 Creating and Writing to XML Files
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 16 Creating and Writing to XML Files
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 17 Creating and Opening an XML File Type lines 60 through 72, as shown below:
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 18 Formatting and Initializing an XML Object Type lines 68 through 72, as shown below:
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 19 Writing an XML Element with an Attribute Type lines 73 through 79, as shown below:
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 20 Writing an XML String Element with No Attributes Type lines 80 and 81, as shown below:
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 21 Writing the Final XML Elements for Hourly Employee Data Type lines 83 through 92, as shown below:
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 22 Writing Salaried Employee Data and Closing the XmlTextWriter Object Type lines 94 through 116, as shown below:
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 23 Setting the Startup Project and Command-Line Arguments for Testing Right-click the CompensationUpdateProcessing project in the Solution Explorer window Click the Set as Startup Project command on the shortcut menu Click the Property Pages button in the Properties window. When the CompensationUpdateProcessing Property Pages dialog box appears, click the Configuration Properties folder Type /x 07/30/2005 in the Command line arguments box Click the OK button
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 24 Setting the Startup Project and Command-Line Arguments for Testing
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 25 Building, Saving, and Testing the Console Application Right-click the CompensationUpdateProcessing project in the Solution Explorer. When the shortcut menu appears, click the Build command Click the Start button on the Visual Basic.NET Standard toolbar Minimize the Visual Basic.NET window. Click the Command Prompt command on the Accessories menu of the Windows Start menu. When the Command Prompt window appears, type A: and press the ENTER key. Type cd\Chapter12\Compensation Review\CompensationUpdateProcessing\bin to change the current folder to the location of the executable file for the CompensationUpdateProcessing application
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 26 Building, Saving, and Testing the Console Application Type CompensationUpdateProcessing /t 07/30/2005 and press the ENTER key. Using the Windows Notepad application, open the file, A:\Chapter12\CompensationUpdate.txt, on the Data Disk Close the Notepad application. In the Command Prompt window, type CompensationUpdateProcessing /c 07/30/2005 and press the ENTER key. Type CompensationUpdateProcessing /r and press the ENTER key
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 27 Building, Saving, and Testing the Console Application Using the Windows Notepad application, open the file, A:\Chapter12\CompensationUpdate.txt on the Data Disk Close the Notepad application. In the Command Prompt window, type CompensationUpdateProcessing/x 07/30/2005 and press the ENTER key Using the Open command on the File menu of the Notepad application, open the file, A:\Chapter12\CompensationUpdate.xml on the Data Disk Click the Close button on the Notepad application window title bar. Click the Close button on the Command Prompt application window title bar. Maximize the Visual Basic.NET application
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 28 Documenting the Console Application Use the Print command on the File menu to print a record of the code for the Console application
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 29 Creating a Web Service
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 30 Starting a New ASP.NET Web Service Project Right-click the Compensation Review solution in the Solution Explorer window. When the shortcut menu appears, click the Add command. When the Add submenu appears, click the New Project command When the Add New Project dialog box appears, click the ASP.NET Web Service icon in the Templates area. Select the text, WebApplication1, in the Location text box. Type CompensationUpdateService in the Location box
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 31 Starting a New ASP.NET Web Service Project Click the OK button Right-click the Service1.asmx file in the Solution Explorer window. When the shortcut menu appears, click the Rename command. Enter CompensationUpdateService.asmx as the new file name Click the click here to switch to code view link in the main work area
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 32 Starting to Code a Web Service Type lines 1 through 3 and modify line 5, as shown below:
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 33 Declaring a Function in a Web Service Select lines 43 through 51 in the code window and then press the DELETE key. Type lines 43 through 45, as shown below:
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 34 Reading and Processing an XML Document Type lines 44 through 55, as shown below:
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 35 Saving and Testing the Web Service Click the Save All button on the Standard Toolbar. Right-click the CompensationUpdateProcessing project in the Solution Explorer window. When the shortcut menu appears, click the Set as Startup Project command Click the Start button on the Visual Basic.NET Standard toolbar Click the GetCompensationUpdate link Click the Invoke button
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 36 Saving and Testing the Web Service Click the Close button on both the Microsoft Internet Explorer application window title bars. If necessary, click the Visual Basic.NET taskbar button to display the Visual Basic.NET window. If necessary, close the Output window
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 37 Documenting the Web Service and Quitting Visual Basic.NET Use the Print command on the File menu to print a record of the code for the CompensationUpdateService Web service Click the Visual Basic.NET Close button
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 38 Summary Start a new Console application Use parameters in a Console application Write code to create a comma-delimited text file Write code to create a tab-delimited text file Write code to create an XML file
Chapter 12: Creating Console Applications, Understanding XML, and Creating Web Services 39 Summary Start a new ASP.NET Web service application Understand the structure of XML files Write code to read an XML file Use a Web service in code Debug Console applications and Web services
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 12 Complete