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.
'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 ...