Chapter 3 -- Service Applications

[Previous] [Next]

Chapter 3

The Microsoft Windows operating system offers various facilities that make implementing the server-side portion of a client-server application easier. As you know, a server is a Windows application that performs server-side duties. Microsoft recommends that server applications be implemented as services. In fact, the Microsoft BackOffice Logo program requires that server applications be implemented as services.

A service is a normal Windows application containing additional infrastructure that enables it to receive special treatment by the operating system—for example, the ability to be remotely administered, allowing an administrator to start or stop the application from a remote machine. By turning your server application into a service, you'll get this and other features for free. This chapter describes what a service application is, how to design a service application, and what additional facilities the operating system offers to services.

Out of the box, Windows includes a number of services. Table 3-1 lists some of the services installed on my machine running Microsoft Windows 2000 and the name of the executable files containing the code for the services.

Table 3-1. Services and associated executable files

Service Name Description Executable Name
Alerter Notifies users and computers of administrative alerts Services.exe
ClipBook Allows pages to be seen by remote ClipBook viewers ClipSrv.exe
Computer Browser Maintains a list of computers on your network Services.exe
DHCP Client Registers and updates IP addresses and DNS names Services.exe
Distributed Transaction Coordinator Coordinates transactions distributed across two or more databases, message queues, file systems, or other transaction-protected resource managers MSDTC.exe
Event Log Logs event messages issued by programs and Windows Services.exe
Messenger Sends and receives messages transmitted by administrators or the Alerter service Services.exe
Net Logon Supports pass-through authentication of account logon events for computers in a domain LSASS.exe
Plug and Play Manages device installation and configuration, and notifies programs of device changes Services.exe
Remote Procedure Call (RPC) Provides the endpoint mapper and other miscellaneous RPC services SvcHost.exe
Remote Procedure Call (RPC) Locator Manages the RPC name service database Locator.exe
Server Provides RPC support and file, print, and named pipe sharing Services.exe
Task Scheduler Enables a program to run at a designated time MSTask.exe
Telephony Provides Telephony API (TAPI) support SvcHost.exe
Uninterruptible Power Supply Manages an uninterruptible power supply (UPS) connected to the computer UPS.exe
Windows Installer Installs, repairs, and removes software according to instructions contained in .msi files MSIExec.exe
Windows Management Instrumentation Provides system management information WinMgmt.exe
Workstation Provides network connections and communications Services.exe

Microsoft produces many more services than the ones I listed in Table 3-1: Microsoft Exchange Server, Microsoft Merchant Server, and Microsoft SQL Server, to name a few. All these server applications are implemented as services and are part of Microsoft BackOffice Suite.

First and foremost, a service application is just a 32-bit or 64-bit executable, so everything you already know about DLLs, structured exception handling, memory-mapped files, virtual memory, device I/O, thread-local storage, thread synchronization, Unicode, and other Windows facilities is available to a service. And this means that converting an existing server application into a service should be relatively easy and straightforward for you.

NOTE
The Microsoft Windows 2000 Resource Kit contains a utility named SrvAny.exe that allows an existing application to be started remotely, just like a true service. However, SrvAny does not allow an application to be remotely administered in any other way, and therefore should be used as a short-term solution only. You are strongly encouraged to modify your application's code to turn it into a full-fledged service and ignore the SrvAny utility altogether.

Second, you need to know that a service should have absolutely no user interface. Most services run on a server machine locked away in a closet somewhere. So if your service presented any user interface elements, such as message boxes, no user would be in front of the machine to see and then dismiss them. And, as you'll see later in this chapter, any windows created would probably appear on a window station or desktop different from the one the user was sitting in front of, and thus the message wouldn't be visible to the user anyway. Because a service won't have a user interface, it doesn't matter whether you choose to implement your service as a graphical user interface (GUI) application (with (w)WinMain as its entry point) or as a console user interface (CUI) application (with (w)main as its entry point).

If a service is not supposed to present any user interface, how do you configure the service? How can you start and stop a service? How can the service issue warnings or error messages? How can the service report statistical data about its performance? The answer to all these questions is that a service can be remotely administered. Windows offers a number of administrative tools that allow a service to be managed from other machines connected on the network so that it is not necessary for someone to physically check (or even have physical access to) the computer running the service. You are probably already familiar with many of these tools: the Microsoft Management Console (MMC), with its Services, Event Viewer, and System Monitor snap-ins; the registry editor; and the Net.exe command-line tool.

These facilities are provided by Windows to simplify the development effort of the service writer. They also give an administrator a consistent way to manage machines remotely and locally. Note that these facilities are not exclusive to services: any application (or device driver) can take advantage of them. These facilities are discussed throughout the chapters of this book.



Programming Server-Side Applications for Microsoft Windows 2000
Programming Server-Side Applications for Microsoft Windows 2000 (Microsoft Programming)
ISBN: 0735607532
EAN: 2147483647
Year: 2000
Pages: 126

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