static void Main(string[] args) { //HttpChannel channel = new HttpChannel(); //TcpChannel channel = new TcpChannel(); IpcChannel channel = new IpcChannel(); ChannelServices.RegisterChannel(channel, false); // Registers the remote class. (This could be done with a // configuration file instead of a direct call.) RemotingConfiguration.RegisterWellKnownClientType( Type.GetType("RemotingClass.ClassTobeRemoting, RemotingClass"), "ipc://localhost:8080/object1uri"); // Instead of creating a new object, this obtains a reference // to the server's single instance of the ServiceClass object. ClassTobeRemoting object1 = new ClassTobeRemoting(); try { Console.WriteLine("ServerTime: " + object1.GetServerTime()); } catch (Exception ex) { Console.WriteLine("Exception of type: " + ex.ToString() + " occurred."); Console.WriteLine("Details: " + ex.Message); } }
static void Main(string[] args) { Hashtable channelProperties = new Hashtable(); channelProperties["secure"] = true; channelProperties["name"] = "ClassConfiguratorRemoting" + GetUniqueClientID(); channelProperties["portName"] = "ClassConfiguratorRemoting" + GetUniqueClientID(); //HttpChannel channel = new HttpChannel(8080); //TcpChannel channel = new TcpChannel(8080); IpcChannel channel = new IpcChannel("localhost:8080"); ChannelServices.RegisterChannel(channel, false); ClassTobeRemoting object1 = new ClassTobeRemoting(); // Creates the single instance of ServiceClass. All clients // will use this instance. ObjRef ref1 = RemotingServices.Marshal(object1, "object1uri"); Console.WriteLine("ObjRef.URI: " + ref1.URI); Console.WriteLine("Running. Press Enter to end publication."); Console.ReadLine(); // This unregisters the object from publication, but leaves // the channel listening. RemotingServices.Disconnect(object1); Console.WriteLine(); Console.WriteLine("Disconnected the object. Client now receives a RemotingException."); Console.WriteLine("Press Enter to unregister the channel."); Console.ReadLine(); // At this point, the ServerClass object still exists. The server // could republish it. // This unregisters the channel, but leaves the application // domain running. ChannelServices.UnregisterChannel(channel); Console.WriteLine("Unregistered the channel. Client now receives a WebException."); // The ServerClass object still exists. The server could // reregister the channel and republish the object. Console.WriteLine("The host application domain is still running. Press Enter to stop the process."); Console.ReadLine(); // The ServiceClass object's Finalize method writes a message to // the console. A single object will almost always succeed in // running its Finalize method before the Console is finalized; // in a larger application, you could ensure that all objects // finalize before the application ends by calling the garbage // collector and waiting. GC.Collect(); GC.WaitForPendingFinalizers(); }