Remoting is a framework built into Common Language Runtime (CLR) in order to provide developers classes to build distributed applications and wide range of network services. Remoting provides various features such as Object Passing, Proxy Objects,Activation, Stateless and Stateful Object, Lease Based LifeTime and Hosting of Objects in IIS. I’m not going into detail of these features because it will take 3 to 4 tutorials. Here I’m presenting a simple client/server based application in orderto provide you easy and fast hands on Remoting.
Remoting Object
This is the object to be remotely access bynetwork applications. The object to be accessed remotely must bederived by MarshalByRefObject and all the objects passed by value mustbe serializable.
using System; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp; namespace RemotingSamples { public class RemoteObject : MarshalByRefObject { ///constructor public RemoteObject() { Console.writeline("Remote object activated"); } ///return message reply public String ReplyMessage(String msg) { Console.WriteLine("Client : "+msg);//print given message on console return "Server : Yeah! I'm here"; } } }
The remote object must be compiled as follows to generate remote object.dll which is used to generate server and client executable.
csc /t:library /debug /r:System.Runtime.Remoting.dll remoteobject.cs
Server
This is the server application used toregister remote object to be access by client application.
Continues…