Server.cs using System; using System.Runtime.Remoting;public class Server{ public static void Main(string[] Args){// Load the configuration file RemotingConfiguration.Configure("server.exe.config");Console.WriteLine("The server is listening. Press Enter to exit...."); Console.ReadLine(); Console.WriteLine("GC'ing."); GC.Collect(); GC.WaitForPendingFinalizers();} } 表2:Server.exe.config源代码 <SYSTEM.RUNTIME.REMOTING> <APPLICATION> <SERVICE> <ACTIVATED type="ClientActivatedType, RemoteType"> </SERVICE> <CHANNELS> <CHANNEL ref="http" port="8088"> </CHANNELS> </APPLICATION> </SYSTEM.RUNTIME.REMOTING> </CONFIGURATION> 表3:RemoteType.cs源代码 using System; using System.Runtime.Remoting.Lifetime; using System.Security.Principal;public class ClientActivatedType : MarshalByRefObject{private int i; // override the lease settings for this object public override Object InitializeLifetimeService(){ return null; } public string RemoteMethod(){// announce to the server that we've been called. Console.WriteLine("ClientActivatedType.RemoteMethod called.");// report our client identity namei=this.GetHashCode(); return "RemoteMethod called. " + i; } public string RemoteMethod1(){ return "RemoteMethod1 called. " + i;} }
表1:Server.cs源代码
Server.cs
using System;
using System.Runtime.Remoting;public class Server{
public static void Main(string[] Args){// Load the configuration file
RemotingConfiguration.Configure("server.exe.config");Console.WriteLine("The server is listening. Press Enter to exit....");
Console.ReadLine(); Console.WriteLine("GC'ing.");
GC.Collect();
GC.WaitForPendingFinalizers();}
}
表2:Server.exe.config源代码
<SYSTEM.RUNTIME.REMOTING>
<APPLICATION>
<SERVICE>
<ACTIVATED type="ClientActivatedType, RemoteType">
</SERVICE>
<CHANNELS>
<CHANNEL ref="http" port="8088">
</CHANNELS>
</APPLICATION>
</SYSTEM.RUNTIME.REMOTING>
</CONFIGURATION>
表3:RemoteType.cs源代码
using System;
using System.Runtime.Remoting.Lifetime;
using System.Security.Principal;public class ClientActivatedType : MarshalByRefObject{private int i;
// override the lease settings for this object
public override Object InitializeLifetimeService(){
return null;
} public string RemoteMethod(){// announce to the server that we've been called.
Console.WriteLine("ClientActivatedType.RemoteMethod called.");// report our client identity namei=this.GetHashCode();
return "RemoteMethod called. " + i;
} public string RemoteMethod1(){
return "RemoteMethod1 called. " + i;}
}