Deploying Windows Services

   


Unlike a Web service, a Windows service application is installed in a directory on the file system of the target computer. Therefore, you use a Setup Project template instead of a Web Setup Project template to deploy a Windows service.

In addition, you also need to register a Windows service with the Windows Service Control Manager. The .NET Framework provides custom installation components to take care of this. These components need to be installed using a custom action in the Setup project.

I already discussed how to install a Windows service in Chapter 6. For a bit of background, I would recommend that you complete Step by Step 6.1 and Step by Step 6.2 if you have not already done so. In this section, I'll use the OrderService Windows service from Chapter 6 and discuss how to package it in a Windows installer package.

STEP BY STEP

10.17 Creating a Setup Project for the OrderService Windows Service

  1. Add an existing Windows service project StepByStep6-1 ( OrderService , created in Chapter 6) to the solution.

  2. Launch WordPad; then create and add a file named License.rtf to the StepByStep6-1 project folder with the following text:

     OrderService End User License Agreement You should carefully read the following terms and conditions before using this software. If you do not agree to any of the terms of this License, then do not install, distribute or use this copy of OrderService. This software, and all accompanying files, data and materials, are distributed "AS IS" and with no warranties of any kind, whether express or implied. Good data processing procedure dictates that any program be thoroughly tested with non-critical data before relying on it.  The user must assume the entire risk of using the program. (c) All rights reserved. 
  3. Add a new project to the solution. In the Add New Project dialog box, select Setup and Deployment projects from the Project Types tree and select Setup and Deployment Projects from the list of templates on the right. Name the project OrderServiceSetup .

  4. In Solution Explorer, right-click the project and select Add, Project Output from the context menu. In the Add Project Output Group dialog box, select StepByStep6-1 as the project and select Primary Output from the list box. Click OK.

  5. In Solution Explorer, right-click the project and select Add, File from the context menu. In the Add Files dialog box, select the License.rtf added to the StepByStep6-1 project in step 2. Click Open.

  6. Select the OrderServiceSetup project in Solution Explorer. Open the User Interface Editor by clicking the User Interface Editor icon in Solution Explorer.

  7. Right-click the Start node under the Install tree and select Add Dialog from the context menu. The Add Dialog dialog box appears. Select License Agreement, as shown in Figure 10.29. Click OK. Right-click License Agreement and choose Move Up Twice to move the License Agreement dialog box to appear after the Welcome dialog box, as shown in Figure 10.30. Select the LicenseFile property in the Properties window and select (Browse...) from the drop-down list. The Select Item in Project dialog box appears. Navigate to the Application Folder and select License.rtf .

    Figure 10.29. You can use the Add Dialog dialog box to add dialog boxes in the User Interface Editor.

    Figure 10.30. You can customize the user interface of the installation program via the User Interface Editor.

    NOTE

    The LicenseFile Property The LicenseFile property of the User Interface dialog box works only with Rich Text Format (RTF) files. If you specify a file of any other format, you don't get any error, but the contents of the file are not displayed in the license agreement.

  8. Open the Custom Actions Editor by clicking the Custom Actions Editor icon in Solution Explorer.

  9. Right-click the Custom Actions node in the editor and select Add Custom Action from the context menu. In the Select Item in the Project dialog box, select Primary Output from StepByStep6-1 (Active) under the Application Folder. Click OK.

  10. Select the new project in Solution Explorer. Activate the Properties window. Set Manufacturer to OrderService Corp , ProductName to OrderService , and Title to OrderService Windows Service .

  11. Build the OrderServiceSetup project. Install the project. A License Agreement screen appears. Only after you select the I Agree option is the Next button enabled, as shown in Figure 10.31.

    Figure 10.31. The customized License Agreement dialog box is added to the user interface to display the license agreement during the installation process.

  12. Click Next; you should notice the Select Installation Folder screen as shown in Figure 10.32. Change the installation folder if you want to, click Next, and then click Close.

    Figure 10.32. The Select Installation Folder screen allows the user to specify a custom installation folder during the installation process.

  13. Open the Services administrative tool from the Administrative Tools section of the Windows Control Panel. You should see the OrderService being added to the Services on the target machine.

In Step by Step 10.17, you learned how to install the predefined installation component using the Custom Actions Editor. In addition, you also learned how to use the User Interface editor to display custom screens such as a License Agreement screen during the setup process.

REVIEW BREAK

  • Installation components allow you to take custom actions during the setup of an application. The .NET Framework provides a few predefined Installer components for use with server components. You can also create custom installation components by deriving from the Installer class.

  • The Windows Installer Service and the Installer tool ( installutil.exe ) perform installation in a transactional manner.

  • If you want a custom installer class to execute when an assembly is installed using a Web Setup project or by using the Installer Tool, you need to apply the RunInstallerAttribute to the class and set its value to true.

  • You use the Setup Project template to create a setup program for a Windows Service.


   
Top


MCAD. MCSD Training Guide (Exam 70-310. Developing XML Web Services and Server Components with Visual Basic. NET and the. NET Framework)
MCAD/MCSD Training Guide (70-310): Developing XML Web Services and Server Components with Visual Basic(R) .NET and the .NET Framework
ISBN: 0789728206
EAN: 2147483647
Year: 2002
Pages: 166

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