做头像网站,手机自适应网站建设维护,做网站赚谁的钱,网站建设视频此示例主要演示了net remoting,其中包含一个服务器程序Server.exe和一个客户端程序CAOClient.exe。客户端程序会通过http channel调用服务器端RemoteType.dll的对象和方法。服务器端的代码文件由下图所述#xff1a;Server.cs源代码 :using System;using System.Runtime.Remot…此示例主要演示了net remoting,其中包含一个服务器程序Server.exe和一个客户端程序CAOClient.exe。客户端程序会通过http channel调用服务器端RemoteType.dll的对象和方法。服务器端的代码文件由下图所述Server.cs源代码 :using System;using System.Runtime.Remoting;public class Server{public static void Main(string[] Args){// Load the configuration fileRemotingConfiguration.Configure(server.exe.config);Console.WriteLine(The server is listening. Press Enter to exit....);Console.ReadLine(); Console.WriteLine(GCing.);GC.Collect();GC.WaitForPendingFinalizers();}} Server.exe.config源代码:
SYSTEM.RUNTIME.REMOTINGAPPLICATIONSERVICEACTIVATED typeClientActivatedType, RemoteType/SERVICECHANNELSCHANNEL refhttp port8088/CHANNELS/APPLICATION/SYSTEM.RUNTIME.REMOTING/CONFIGURATIONRemoteType.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 objectpublic override Object InitializeLifetimeService(){return null;}public string RemoteMethod(){// announce to the server that weve been called.Console.WriteLine(ClientActivatedType.RemoteMethod called.);// report our client identity nameithis.GetHashCode(); return RemoteMethod called. i;}public string RemoteMethod1(){return RemoteMethod1 called. i;}}客户端代码文件由下图所示CAOClient.cs源代码using System;using System.Runtime.Remoting;using System.Runtime.Remoting.Lifetime;public class Client{public static void Main(string[] Args){// Load the configuration fileRemotingConfiguration.Configure(CAOclient.exe.config); ClientActivatedType CAObject new ClientActivatedType();Console.WriteLine(Client-activated object: CAObject.RemoteMethod());Console.WriteLine(Client-activated object: CAObject.RemoteMethod1());Console.WriteLine(Press Enter to end the client application domain.);Console.ReadLine();}}CAOClient.exe.config源代码:CONFIGURATIONSYSTEM.RUNTIME.REMOTINGAPPLICATIONCLIENT urlhttp://localhost:8088ACTIVATED typeClientActivatedType, RemoteType/CLIENTCHANNELSCHANNEL refhttp port0/CHANNELS/APPLICATION/SYSTEM.RUNTIME.REMOTING/CONFIGURATION OK,编译以上代码文件使用“Visual Studio .net Command Prompt分别编译上述文件:csc /target:library RemoteType.cscsc Server.cscsc –reference:RemoteType.dll CAOClient.cs您会看到三个输出文件RemoteType.dll, Server.exe 和 CAOClient.exe。运行Remoting程序在命令行方式下启动Server.exe在命令行方式下启动CAOClient.exe