One Community, One World
Overview of .Net Remoting
by Ahmed Rafie  on Sep 14 2006 12:00AM
  PageViews 8823   |    Add to Fav   |     Send to Friend   |    no downloads available

In this article I will explain the fundamentals of Microsoft .Net Remoting framework, which is one of the most interesting technologies that .net framework introduced. Remoting enables you to develop distributed applications by providing a framework that allows objects to communicate through across application domains (whether the objects in the same computer or spread out the entire world).

Before we start to continue talking about Remoting framework I'd like to begin with the definition of distributed application, which is an application made up of distinct components running in separate runtime environments, usually on different platforms connected via a network. Typical distributed applications are two-tier (Client-Server), three-tier (client-middleware-server), and multi-tier (client-multiple middleware-multiple servers) (Wikipedia).

Microsoft in the .NET framework provides many distributed application technologies, which I will make a comparison between them. 

XML Web Services
XML Web services are units of application logic that provide data and services to other applications. Applications access XML Web services by using standard Web protocols and data formats such as Hypertext Transfer protocol (HTTp), XML, and Simple Object Access protocol (SOAp), independent of how each Web service is implemented. XML Web services combine the best aspects of component-based development and the Web and are a cornerstone of the Microsoft .NET programming model.

Serviced Components
A serviced component is a .NET Framework component that is hosted in COM+ and is designed to use COM+ services. COM+ services facilitate the development of distributed Applications by providing a ready-to-use enterprise application infrastructure.
The Remoting framework provides an abstract approach to interprocess communication that separates the remote object from a specific server and client process and from a specific communication mechanism. 

When to use?
Each of these technologies has advantages and disadvantages, this is the critical part, when you are designing a distributed application you must be familiar with all of these technologies. 

XML Web Services      : use it when applications need to interact over a wide range of platforms and operating systems.
Serviced components : use it when you want to use one of COM+ services.
Remoting                    : use it when data exchange occurs between .net applications. 

Architectural overview of Remoting

Remote Object
To enable the client object to access the functionality of the server object across process boundaries, the server object must be remotable. There are two types of remotable

  • Marshal-by-Value (MBV) : When the server object is Marshal-by-value object, the server's Remoting system uses serialization, in which the server's Remoting system encodes the object into a sequence of bits and transfer it to the client who decodes that sequence of bits and then call the methods.
  •  Marshal-by-Reference(MBR) :In this type of server objects, the server's Remoting system sends a reference of the Remoting object to the client Remoting system. The client object then uses this reference to call the methods in the server object.

Channel Protocols
Framework provides channels through which messages can travel to and from remote objects. To marshal remote objects across application domains, you must attach the messages to specific channel. A channel has a server object at one end and a client object at the other.
In Remoting, the server object specifies a protocol and port number for receiving a request. The client object sends the request to the server object by using the specified protocol and port number; there are two channels protocols in Remoting.

  • HTTP Channels: Use HTTP channels when you want to communicate over Internet, because firewalls do not hinder HTTP communications.
  • TCP Channels: Use TCp channels when you want to communicate within an intranet. If you use TCp channels, you may have to open specific ports in the firewalls between the client and the server.

In .Net Remoting, you must convert data to an appropriate format before transmitting it over a channel. Formatters are objects that encode and serialize data into the appropriate format. Formatters must implement the IFortmatter interface before transmitting the data. .Net framework provides two formatters classes:

  • SOAP Formatter: This class based on SOAP. This protocol is extensible and modular and does not depend on any specific transport protocol, such as HTTP or TCP. SOAP is ideal protocol for communication between applications that use incompatible architectures. Because it is an XML-based protocol, SOAp is text-base.
  • Binary Formatter:This class uses binary messages to transfer information. It is simple and more efficient that the SOAP format. However, only framework applications can read the binary format.

When the client object activates a server object, a proxy is created in the client’s process. The proxy acts as representatives of the server object and forwards all calls made
by the client object to the server object.

What Is Activation ?
Is the process of creating and initializing an object. The Remoting system must know what type of activation is required before it can make the objects available to clients;
there are two types of activation modes: server activation and client activation. 

  • Server-Activated Objects : objects are exists in the server address space, and inherits from MarshalByRefObject, the client access these objects by reference through a proxy. The server application domain creates SAO only when client makes a method call on the object, not when the client call the new function. There are two activation modes for SAOs: SingleCall and Singleton
    • SingleCall : each time the client request an object, new instance created for this request. All subsequence client requests will be serviced by a different object instance even if the server has not yet recycled the pervious instance.
    • Singleton : have only one instance at any given time. If an instance exits, that instance will service all client requests. If an instance does not exist, the server creates an instance that services all subsequent client requests.
  • Client-activated objects : Are remote objects that are activated upon request from the client. With client activation, when the client tries to create an instance of the remote object, a two-way communication occurs between the client and the server. When the client requests a remote object, the remote application receives an activation message. The server then creates an instance of the requested class and returns an object reference to the client application that invoked it. The client side then creates a proxy.

Now you have a complete vision about Remoting framework and its components.

Future of .Net Remoting
The upcoming version of Microsoft Windows, will include a unified programming Model and communications infrastructure for developing connected systems. Which called Windows communication foundation (WCF), formerly code-named "Indigo," is about to radically change the face of distributed programming for developers using the Microsoft .NET Framework. WCF unifies the existing suite of .NET distributed technologies into a single programming model that improves the overall developer experience through a consistent architecture, new levels of functionality and interoperability, and all the extensibility points you could want.