Thursday, March 12, 2009

.Net Remoting


HI,


In this post we will see what .Net Remoting is and go through an example.


Basics


.Net Remoting provides you the way to build distributed application, either on the same computer or across the entire world. Your client application can use the objects from other application/processes on the same computer or any computer that is reachable over the network. Basically Remoting allows or gives platform to communicate with other application domains easily.


Code running in one application cannot directly access code or resources from another application. The common language runtime enforces this isolation by preventing direct calls between objects in different application domains. Objects that pass between domains are either copied or accessed by proxy. If the object is copied, the call to the object is local. That is, both the caller and the object being referenced are in the same application domain. If the object is accessed through a proxy, the call to the object is remote. In this case, the caller and the object being referenced are in different application domains. Cross-domain calls use the same remote call infrastructure as calls between two processes or between two machines.


Remoting allows you to choose any of the application models for communication; you can use Web application, Windows application or Console application for communication between the objects/application. Similarly, Remoting servers can also be any type of application domain. Any application can host remoting objects and provide its services to any client on its computer or network.


While using .Net Remoting where two components communicate directly with each other you need to build three things:

- Remotable Object

- Host application domain: Listen to the request from the client application to provide object.

- Client application domain: Makes request to the host for getting the object.


The real strength of the remoting system, however, resides in its ability to enable communication between objects in different application domains or processes using different transportation protocols, serialization formats, object lifetime schemes, and modes of object creation. In addition, remoting makes it possible to intervene in almost any stage of the communication process, for any reason.


Architecture


Communication between client and server object references is the base of the Remoting. Once you start or create server object and client receive the reference to the same, your application will be ready to use all resources and functionality of the server object.


.Net Remoting uses the proxy objects to create an instance of the remote type:

- Proxy objects to create the impression that the server object is in the client's process.

- Proxies are stand-in objects that present themselves as some other object.

- When client creates an instance of the remote type or server object, .Net Remoting creates a proxy object, which looks very similar like remote type.

- Client calls methods on proxy object then:

1. Remoting system receives the call,

2. Routes it to the server process,

3. Invokes the server object,

4. Returns the return value/object to client proxy,

5. And finally client proxy returns the value/object to client.


While doing all these things, .Net Remoting requires opening a network connection and use the particular protocol to the receiving application, is called transport channel. A channel is a type that takes a stream of data, creates a package according to a particular network protocol, and sends the package to another computer. Some channels can only receive information, others can only send information, and still others, such as the default TcpChannel and HttpChannel classes, can be used in either direction.


Although the server process knows everything about each unique type, the client knows only that it wants a reference to an object in another application domain, perhaps on another computer. From the world outside the server application domain, a URL locates the object. The URLs that represent unique types to the outside world are activation URLs, which ensure that your remote call is made to the proper type.


Below image shows the general remoting process:















Above figure shows the complete flow in the .Net Remoting, if the network connection is set properly, remoting system creates a proxy object and returns it to the client object. Client uses this proxy object as remote type, calls its method’s, the call gets transfers from client to proxy object and then remoting system transfers the call to the server object and returns the return value/object.


Here, channel is shown as the communication link between the Client Object and Server Object which runs over the TCP-IP protocol.


In the next post we will the working example of the .Net Remoting.


Thanks,


Paresh Bhole

No comments:

Hello

Thanks for checking out my post...

... Paresh Bhole