O'Reilly logo

Object-Oriented Programming with Visual Basic .NET by J.P. Hamilton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

9.3. Windows Services

It is possible to write a server that runs within a console window in a few lines of code. However, it is neither realistic nor practical because there is no easy way of administering a server running in this environment. Using a Windows Service provides more of a real-world scenario, so considerable time will be spent developing one. The classes in the next few examples form the basis of a service that can be used to host all kinds of objects generically. The code is completely reusable and extensible.

To make building a Windows Service easier, Example 9-2 contains the listing for an abstract base class called ObjectServer that is specifically designed to build services that remote objects. Like all Windows Services, it inherits from System.ServiceProcess.ServiceBase. The class also provides both an HttpChannel and a TCPChannel object instance so objects can be remoted with each protocol.

Example 9-2. Windows Service base class for remotable objects
'Windows Service Base Class for Remoting Objects ' 'Compile: 'vbc /t:library /r:system.dll /r:System.Serviceprocess.dll '/r:System.Runtime.Remoting.dll objectserver.vb ' 'Install: 'installutil objectserver.exe ' 'Uninstall: 'installutil /u objectserver.exe Imports System Imports System.Diagnostics Imports System.Runtime.Remoting Imports System.Runtime.Remoting.Channels Imports System.Runtime.Remoting.Channels.Http Imports System.Runtime.Remoting.Channels.Tcp Imports System.ServiceProcess Namespace ObjectServerSpace ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required