home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 June (DVD) / DPPRO0605DVD.iso / Install / program files / Borland / BDS / 3.0 / Demos / Delphi.Net / CLR / Remoting / uTCPService.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2004-10-22  |  3.1 KB  |  128 lines

  1. unit uTCPService;
  2. //------------------------------------------------------------------------------
  3. //  Last updated:   11/06/03
  4. //  Author:         Dennis Passmore
  5. //  Company:        Ultimate Software, Inc.
  6. //  Contact info:   dennis_passmore@ultimatesoftware.com
  7. //
  8. //  Compatibility:  Delphi for .NET TCP service demo
  9. //
  10. //  Description:    ServiceInstaller for TmpService application
  11. //
  12. //------------------------------------------------------------------------------
  13. interface
  14.  
  15. uses
  16.   Borland.VCL.Sysutils,
  17.   System.Configuration,
  18.   System.ServiceProcess,
  19.   System.Collections.Specialized,
  20.   System.Runtime.Remoting,
  21.   System.Runtime.Remoting.Channels,
  22.   System.Runtime.Remoting.Channels.TCP,
  23.   System.Runtime.Serialization.Formatters,
  24.   uTCPIntf;
  25.  
  26.  
  27. type
  28.   TNTService = class(System.ServiceProcess.ServiceBase)
  29.   strict protected
  30.     procedure OnContinue; override;
  31.     procedure OnPause; override;
  32.     procedure OnShutdown; override;
  33.     procedure OnStart(args: array of string); override;
  34.     procedure OnStop; override;
  35.   public
  36.     constructor Create;
  37.   end;
  38.  
  39.   THelloService = class(MarshalByRefObject, ITCPService)
  40.     function SayHello(const fItem: string; out aResult: string): boolean;
  41.   end;
  42.  
  43. var
  44.   NTService: TNTService = nil;
  45.   HSobj: THelloService = nil;
  46.  
  47. implementation
  48.  
  49. uses
  50.   uTCPServInst;
  51.  
  52. function THelloService.SayHello(const fItem: string; out aResult: string): boolean;
  53. begin
  54.   aResult := 'Hello ' + fItem;
  55.   Result := true;
  56. end;
  57.  
  58. constructor TNTService.Create;
  59. begin
  60.   inherited Create;
  61.   ServiceName         := cNTServiceProg;
  62.   CanHandlePowerEvent := false;
  63.   CanPauseAndContinue := false;
  64.   CanShutdown         := true;
  65.   CanStop             := true;
  66.   EventLog.Source     := cNTServiceDesc;
  67.   EventLog.Log        := 'Application';
  68.   AutoLog := true;
  69. end;
  70.  
  71. procedure TNTService.OnContinue;
  72. begin
  73.   inherited; // should never be called
  74.   //todo
  75. end;
  76.  
  77. procedure TNTService.OnPause;
  78. begin
  79.   inherited; // should never be called
  80.   // todo
  81. end;
  82.  
  83. procedure TNTService.OnShutdown;
  84. begin
  85.   inherited;
  86.   // todo
  87. end;
  88.  
  89. procedure TNTService.OnStart(args: array of string);
  90. var
  91.   chan: TcpChannel;
  92.   Dictionary: ListDictionary;
  93.   provider: System.Runtime.Remoting.Channels.BinaryServerFormatterSinkProvider;
  94.   AppSettings: AppSettingsReader;
  95.   error, iport: integer;
  96.   sport: string;
  97.   oport: TObject;
  98. begin
  99.   inherited;
  100.   AppSettings := AppSettingsReader.create;
  101.   oport := AppSettings.GetValue('port', typeof(''));
  102.   sport := oport.ToString;
  103.   if sport = '' then
  104.     sport := '8085';
  105.   val(sport,iport,error);
  106.  
  107.   provider := BinaryServerFormatterSinkProvider.create;
  108.   provider.TypeFilterLevel := TypeFilterLevel.Full;
  109.  
  110.   Dictionary := ListDictionary.create;
  111.   Dictionary.Add('port', tobject(iport));
  112.  
  113.   chan := TcpChannel.create(Dictionary, nil, provider);
  114.   ChannelServices.RegisterChannel(chan);
  115.  
  116.   RemotingConfiguration.RegisterWellKnownServiceType(
  117.             typeof(THelloService), 'HelloService',
  118.                              WellKnownObjectMode.SingleCall);
  119. end;
  120.  
  121. procedure TNTService.OnStop;
  122. begin
  123.   inherited;
  124. //  todo
  125. end;
  126.  
  127. end.
  128.