1. Examples (inter-program communication)
classProgram {Static voidMain (string[] args) {HttpChannel _channel=NewHttpChannel (10001); ChannelServices.RegisterChannel (_channel,false); Console.WriteLine ("HTTP Channel Remoting service start ..."); //method RegisterWellKnownServiceType registers the object type on the server as a known typeRemotingConfiguration.RegisterWellKnownServiceType (typeof(Selfremoteobject),"Selfremoteobject", Wellknownobjectmode.singleton); //server-activated objects have two activation modes: Singleton and SingleCall, which are called known objects and are identified by the enumeration type: WellKnownObjectMode. //the singleton type has only one instance at any one time. All client requests will be serviced by this instance. If there is no instance, the server creates one, and all subsequent client requests are serviced by this instance. For a single-piece type, it is associated to the default lifetime. //The SingleCall type creates an instance for each client request. The next method call will be serviced by a different server instance, even if the system has not reclaimed a reference to the previous instance. Test (); Console.read (); } Public Static voidTest () {//using the Actovator.getobject method to get the proxySelfremoteobject app =(Selfremoteobject) Activator.GetObject (typeof(selfremoteobject),"Http://localhost:10001/selfRemoteObject"); Console.WriteLine (App. Plus (1,3)); Console.ReadLine (); } } Public classSelfremoteobject:marshalbyrefobject { Public intPlus (intAintb) {Console.WriteLine ("Client request call: A={0},b={1}", A, b); Console.WriteLine ("calculation result: a+b={0}, returned to the client call", A +b); returnA +b; } }
. NET Remoting (1) Simple example