/// <summary> /// Access the .NET Remoting server using a configuration file. /// </summary> static void AccessRemotingServerByConfig() { // Read the configuration file and configure the remoting // infrastructure for the client project. // The format for .NET Remoting configuration file: // http://msdn.microsoft.com/en-us/library/ms973907.aspx RemotingConfiguration.Configure("CSRemotingClient.exe.config", true); try { // // Create a remotable object. // // Create a SingleCall server-activated proxy. SingleCallObject remoteObj = new SingleCallObject(); Console.WriteLine("A SingleCall server-activated proxy is created"); // [-or-] Create a Singleton server-activated proxy. //SingletonObject remoteObj = new SingletonObject(); //Console.WriteLine("A Singleton server-activated proxy is created"); // [-or-] Create a client-activated object. //ClientActivatedObject remoteObj = new ClientActivatedObject(); //Console.WriteLine("A client-activated object is created"); // // Use the remotable object as if it were a local object. // string remoteType = remoteObj.GetRemoteObjectType(); Console.WriteLine("Call GetRemoteObjectType => {0}", remoteType); Console.WriteLine("The client process and thread: {0}, {1}", Process.GetCurrentProcess().Id, GetCurrentThreadId()); uint processId; uint threadId; remoteObj.GetProcessThreadID(out processId, out threadId); Console.WriteLine("Call GetProcessThreadID => {0} {1}", processId, threadId); Console.WriteLine("Set FloatProperty += {0}", 1.2f); remoteObj.FloatProperty += 1.2f; Console.WriteLine("Get FloatProperty = {0}", remoteObj.FloatProperty); } catch (SocketException ex) { Console.WriteLine(ex.Message); } }
/// <summary> /// Access the .NET Remoting server using configuration file. /// </summary> static void RemotingClientByConfig() { ///////////////////////////////////////////////////////////////////// // Reads the configuration file and configures the remoting // infrastructure for the client end. // // The format for .NET Remoting configuration file: // http://msdn.microsoft.com/en-us/library/ms973907.aspx RemotingConfiguration.Configure("CSRemotingClient.exe.config", true); ///////////////////////////////////////////////////////////////////// // Create a remotable object. // // Create a SingleCall server-activated object SingleCallObject remoteObj = new SingleCallObject(); // [-or-] a Singleton server-activated object //SingletonObject remoteObj = new SingletonObject(); // [-or-] a client-activated object //ClientActivatedObject remoteObj = new ClientActivatedObject(); ///////////////////////////////////////////////////////////////////// // Use the remotable object as if it were a local object. // string remoteType = remoteObj.GetRemoteObjectType(); Console.WriteLine("Call GetRemoteObjectType => {0}", remoteType); Console.WriteLine("The client process and thread: {0}, {1}", GetCurrentProcessId(), GetCurrentThreadId()); uint processId, threadId; remoteObj.GetProcessThreadID(out processId, out threadId); Console.WriteLine("Call GetProcessThreadID => {0} {1}", processId, threadId); Console.WriteLine("Set FloatProperty += {0}", 1.2f); remoteObj.FloatProperty += 1.2f; Console.WriteLine("Get FloatProperty = {0}", remoteObj.FloatProperty); }
/// <summary> /// Access the .NET Remoting server using code. /// </summary> static void AccessRemotingServerByCode() { // Create and register a channel (TCP channel in this example) that // is used to transport messages across the remoting boundary. // Set the properties of the channel. IDictionary props = new Hashtable(); props["typeFilterLevel"] = TypeFilterLevel.Full; // Set the formatters of the messages for delivery. BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider(); BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider(); serverProvider.TypeFilterLevel = TypeFilterLevel.Full; // Create a TCP channel. TcpChannel tcpChannel = new TcpChannel(props, clientProvider, serverProvider); // Register the TCP channel. ChannelServices.RegisterChannel(tcpChannel, true); try { // // Create a remotable object. // // Create a SingleCall server-activated proxy. SingleCallObject remoteObj = (SingleCallObject)Activator.GetObject( typeof(SingleCallObject), "tcp://localhost:6100/SingleCallService"); Console.WriteLine("A SingleCall server-activated proxy is created"); // [-or-] Create a Singleton server-activated proxy ////SingletonObject remoteObj = (SingletonObject)Activator.GetObject( //// typeof(SingletonObject), //// "tcp://localhost:6100/SingletonService"); ////Console.WriteLine("A Singleton server-activated proxy is created"); // [-or-] Create a client-activated object ////RemotingConfiguration.RegisterActivatedClientType( //// typeof(ClientActivatedObject), //// "tcp://localhost:6100/RemotingService"); ////ClientActivatedObject remoteObj = new ClientActivatedObject(); ////Console.WriteLine("A client-activated object is created"); // // Use the remotable object as if it were a local object. // string remoteType = remoteObj.GetRemoteObjectType(); Console.WriteLine("Call GetRemoteObjectType => {0}", remoteType); Console.WriteLine("The client process and thread: {0}, {1}", Process.GetCurrentProcess().Id, GetCurrentThreadId()); uint processId; uint threadId; remoteObj.GetProcessThreadID(out processId, out threadId); Console.WriteLine("Call GetProcessThreadID => {0} {1}", processId, threadId); Console.WriteLine("Set FloatProperty += {0}", 1.2f); remoteObj.FloatProperty += 1.2f; Console.WriteLine("Get FloatProperty = {0}", remoteObj.FloatProperty); } catch (SocketException ex) { Console.WriteLine(ex.Message); } }