Managing Globally with Information Technology

Team-Fly    

Developing XML Web Services and Server Components with Visual C#™ .NET and the .NET Framework, Exam Cram™ 2 (Exam 70-320)

By Amit Kalani, Priti Kalani

Table of Contents
Chapter 7.  Windows Services

Question 1

You are required to design an application that monitors incoming emails and analyzes them to filter out junk emails. The emails arrive at a well-known port, and you use conditions stored in an XML file to determine whether an email is possibly a junk email. Your application bounces back all junk email while forwarding the other emails to a groupware application. You want this application to run continuously, with minimal interaction with the desktop user. How should you design this application?

  • A. Design the application as a Windows forms application

  • B. Design the application as a Windows service application

  • C. Design the application as a Web forms application

  • D. Design the application as a Web service application

A1:

The correct answer is B. The application in question runs continuously and requires minimal user interaction. The application also just listens to email and is not required to listen to Web-based requests. Given these characteristics, you should design this application as a Windows service rather than any of the application types specified in the other options. Answers A and C are incorrect because these types of applications are suitable when the users directly interact with the application. These applications, along with Web services, are also not suited for implementing a long-running process. Therefore, answer D is also incorrect.

Question 2

You are working on a team that is designing a Windows service that monitors Web server performance on an ongoing basis. You are given a task to make sure that an entry is written to the application event log when the Windows service is started, paused, resumed, or stopped. You want to write a minimal amount of code to achieve this. Which of the following options would you choose?

  • A. Use the EventLog property of the Windows service class to write entries to the Application log.

  • B. Set the AutoLog property of the Windows service class to true.

  • C. Create an EventLog component in the project, and use this component to write entries in the event log.

  • D. Create a method that writes entries in the event log, and call this method from the OnStart(), OnStop(), OnPause(), and OnContinue() methods of the Windows service class.

A2:

The correct answer is B. When you set the AutoLog property to true, the Windows service class automatically writes events to the application event log. Answers A, C, and D are incorrect because they require more code to be written to achieve the same results.

Question 3

You are developing a Windows service application that accepts startup parameters. Which of the following methods would you program to retrieve and process these parameters?

  • A. The Main() method

  • B. The Run() method

  • C. The OnStart() method

  • D. The constructor of the Windows service class

A3:

The correct answer is C. When a Windows service is started, any startup parameters are passed to the OnStart() method. Answers A, B, and D are incorrect because these methods do not receive the startup parameters.

Question 4

You have designed a Windows service application that contains two Windows services. You now want to add installer classes to this application so that the application can be installed with tools such as installutil.exe. You have added a new class inherited from the Installer class in your application. To the Installers collection of this class, you want to add the custom installation components for properly installing the Windows services in your application. Which of the following combinations of custom components would you like to add to the Installers collection of the Installer class?

  • A. Add two instances of the ServiceProcessInstaller class and one instance of the ServiceInstaller class.

  • B. Add two instances of the ServiceInstaller class and one instance of the ServiceProcessInstaller class.

  • C. Add two instances each of the ServiceInstaller class and the ServiceProcessInstaller classes.

  • D. Add one instance each of the ServiceInstaller class and the ServiceProcessInstaller classes.

A4:

The correct answer is B. For installing a Windows service application, you need to have one instance of the ServiceProcessInstaller class and as many instances of the ServiceInstaller class as the number of services you want to install. Answers A and C are incorrect because only one instance of the ServiceProcessInstaller needs to be there. Answer D is incorrect because two instances of the ServiceInstaller class are needed for an application that contains two Windows services.

Question 5

You are required to design a Windows service that cannot be paused. Which of the following options will help you to accomplish this requirement?

  • A. Set the CanStart property of the Windows service to true, but set the CanStop property to false.

  • B. Set the CanPauseAndContinue property of the Windows service to false.

  • C. Do not include definitions for the OnPause() and OnContinue() methods in the class definition of the Windows service.

  • D. Do not include a definition for the OnStop() method in the class definition for Windows service.

A5:

The correct answer is B. If you do not want a Windows service to be paused, you need to set the CanPauseAndContinue property of the Web service to false. If this property is true, the SCM can send pause and continue messages to your service. Answers A and D are incorrect because stopping a Windows service is different from pausing a Windows service. In case of stopping, the Windows service is unloaded from memory and all its resources are reclaimed. Answer C is incorrect because OnPause() and OnContinue() methods are expected to be overridden when the CanPauseAndContinue property is true.

Question 6

You are designing an application that needs to know the Windows services that are installed on a computer. Which of the following classes enables you to retrieve this information?

  • A. ServiceBase

  • B. ServiceInstaller

  • C. ServiceController

  • D. ServiceProcessInstaller

A6:

The correct answer is C. The ServiceController class interacts with the SCM to enumerate the list of services installed on a computer. You get this information by using the static GetServices() method of this class. Answers A, B, and D are incorrect because these classes do not provide any functionality to retrieve the list of services installed on a computer.

Question 7

Your group is designing a Windows service application that constantly monitors the computer to keep it tuned. This service performs tasks such as disk defragmentation, Registry cleanup, and virus detection. The service needs to have a high privilege to perform its task. In what security context should you set up this service to run?

  • A. LocalService

  • B. LocalSystem

  • C. NetworkService

  • D. User

A7:

The correct answer is B. The LocalSystem value defines a highly privileged account. Answers A and C are incorrect because the LocalService and NetworkService values provide a lower privilege level for the security context. Answer D is incorrect because privileges for the User account depend on the specified username and password.

Question 8

Which of the following options correctly identifies the security context in which a Windows service is executed?

  • A. In the context of the built-in SYSTEM account

  • B. In the context of the currently logged-on user

  • C. In the context of the Administrator account

  • D. In the context of the account information specified at the time of service installation

A8:

The correct answer is D. A Windows service always executes by using a user identity that is specified at the time the Windows service is installed. Answer B is incorrect because most Windows services are started before a user logs on, and they keep on running across multiple user sessions. Therefore, the functionality of a Windows service cannot depend on the permissions available to the user currently logged on. Answers A and C are incorrect because some Windows services might need to have fewer privileges available when compared to others. This means that assigning a fixed user account for all the Windows services is not a good idea.

Question 9

You are designing a Windows service application, and you want to set the service to start automatically when the computer is restarted. Which of the following classes enables you to retrieve this information?

  • A. ServiceBase

  • B. ServiceInstaller

  • C. ServiceController

  • D. ServiceProcessInstaller

A9:

The correct answer is B. The StartType property of the ServiceInstaller class is used to specify whether a service will be started manually or automatically, or will not start at all. Answers A, C, and D are incorrect because these classes do not have any property to specify the start type for a Windows service.

Question 10

Your colleague has designed a Windows service application by inheriting a class from the ServiceBase class. She is complaining that she can compile the program successfully, but when she tries to run the program, she gets an error. What should you suggest to resolve this problem? (Select two.)

  • A. Ask your colleague to start the Windows service by using the Service MMC snap-in.

  • B. Ask your colleague to restart the computer.

  • C. Ask your colleague to add custom installation components to the Windows service application and to install the application by using installutil.exe.

  • D. Ask your colleague to modify the Windows Registry by using regedit.exe, and write the Windows service details there.

A10:

The correct answers are A and C. The installutil.exe tool interacts with the SCM to install a Windows service. After the service is installed successfully, you should instruct your colleague to start the Windows service by using the Service MMC snap-in. Answer B is incorrect because if the start type of the service is not set up as automatic, the service will not start automatically when the computer restarts. Answer D is incorrect because manual modifications to the Windows Registry should be avoided as much as possible.


    Team-Fly    
    Top

    Категории