I'm making a Windows Service that runs in the background and handles the .NET Remoting part on the server. This is the code currently available for my service when it starts.
Expand|Select|Wrap|Line Numbers
- protected override void OnStart(string[] args)
- {
- // Write in the EventLog of Windows that the remote service for BigBrother is starting.
- EventLog.WriteEntry("BigBrother Remote Service -- Starting up the Service.");
- // Create a new TCP channel for our service to listen on.
- TcpChannel channel = new TcpChannel(3000);
- EventLog.WriteEntry("BigBrother Remote Service -- Channel created on port 3000");
- // Register the channel so clients can remote access it.
- ChannelServices.RegisterChannel(channel, true);
- EventLog.WriteEntry("BigBrother Remore Service -- Channel registered.");
- // Register our RemoteManager class so clients can talk to it and perform
- // tasks.
- try
- {
- WellKnownServiceTypeEntry srvcEntry = new WellKnownServiceTypeEntry(typeof(RemoteManager), "tcp://localhost:3000/BigBrotherRemoteService", WellKnownObjectMode.SingleCall);
- RemotingConfiguration.RegisterWellKnownServiceType(srvcEntry);
- EventLog.WriteEntry("BigBrother Remote Service -- Listener successfully registered.");
- }
- catch (Exception Ex)
- {
- EventLog.WriteEntry("BigBrother Remote Service -- Failed to register the Listener :: " + Ex.ToString());
- }
- }
Expand|Select|Wrap|Line Numbers
- public class RemoteManager : MarshalByRefObject
- {
- public RemoteManager()
- { }
- public String Test()
- {
- return "Remote Manager greets you.";
- }
- }
Expand|Select|Wrap|Line Numbers
- static void Main(string[] args)
- {
- // Create a channel for communicating with the remote object.
- TcpChannel channel = new TcpChannel();
- ChannelServices.RegisterChannel(channel, true);
- // Create an instance of the remote object.
- BigBrother_Remote_Library.RemoteManager manager = (BigBrother_Remote_Library.RemoteManager)Activator.GetObject(typeof(BigBrother_Remote_Library.RemoteManager), "tcp://localhost:3000/BigBrotherRemoteService");
- // Use the object.
- if (manager.Equals(null))
- {
- System.Console.WriteLine("Failed to retrieve the remote object.");
- }
- else
- {
- System.Console.WriteLine("Calling the Test function on our object.");
- System.Console.WriteLine(manager.Test());
- }
- System.Console.ReadLine();
- }
What am I doing wrong/forgetting?