CHAPTER 18 THE .NET REMOTING LAYER 599 (Post office web site)

CHAPTER 18 THE .NET REMOTING LAYER 599 static class Program { static void Main() { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new CarService() }; ServiceBase.Run(ServicesToRun); } } Implementing CarService.OnStart() You can likely already assume what sort of logic should happen when your custom service is started on a given machine. Recall that the role of CarService is to perform the same tasks as your custom console-based service. Thus, if you wish to register CarService as aWKO-singleton type that is available via HTTP, you could add the following code to the OnStart() method (as you would hope, you may make use of the RemotingConfiguration type to load up a server-side remoting *.config file, rather than hard-coding your implementation, when hosting remote objects using aWindows service): protected override void OnStart(string[] args) { // Create a new HttpChannel. HttpChannel c = new HttpChannel(32469); ChannelServices.RegisterChannel(c); // Register as single call WKO. RemotingConfiguration.RegisterWellKnownServiceType( typeof(CarGeneralAsm.CarProvider), “CarProvider.soap”, WellKnownObjectMode.SingleCall); // Log successful startup. EventLog.WriteEntry(”CarWinService”, “CarWinService started successfully!”, EventLogEntryType.Information); } Note that once the type has been registered, you log a custom message to the Windows event log (via the System.Diagnostics.EventLog type) to document that the host machine successfully started your service. Implementing OnStop() Technically speaking, the CarService does not demand any sort of shutdown logic. For illustrative purposes, let s post another event to the EventLog to log the termination of the custom Windows service: protected override void OnStop() { EventLog.WriteEntry(”CarWinService”, “CarWinService stopped”, EventLogEntryType.Information); } Now that the service is complete, the next task is to install this service on the remote machine.
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

Leave a Reply