Click here to Skip to main content
15,881,092 members
Articles / Programming Languages / C#
Article

.NET Remoting

Rate me:
Please Sign up or sign in to vote.
3.00/5 (1 vote)
1 Jan 2008CPOL3 min read 23.1K   11   1
DCOM component replacement in .NET is .NET remoting

Overview

The replacement of DCOM is .NET Remoting. .NET Remoting can be described as:

  1. Web Services Anywhere
  2. CLR Object Remoting

Using SOAP and HTTP are just one way of calling remote objects out of UDP, IPX and SMTP etc.

CLR object remoting sits on top of Web service anywhere.

All the language constructs can be used with remote objects.

Description

.NET remoting is used to access objects in another application domain. In remote assemblies, the client receives a proxy to talk to. Proxy is a representation of a remote object in the client process, used to call methods. The message is passed to the remote object into the channel.

Architecture of .NET Remoting

  • Remote Object: Remote Object is one, running on the server
  • Channel: Communication path between client and server

Two types of channels for communication are TCP and HTTP.

Custom channels using different protocols are also possible.

  • Message: Messages hold the information about the remote object including name and all of the arguments.
  • Formatter: Formatters define how messages are transferred into the channel. Default is SOAP and binary formatters.
  • Formatter Provider: Formatter Provider associates a Formatter with a channel to send message onto wire.
  • Proxy Object: Proxy Objects are of two types:
    1. Transparent
    2. Real

Transparent proxy is like a remote object to the client. Transparent proxy calls invoke () method on the Real proxy.

  • Message Sink: Message Sink is an interceptor on both the client and server. A message sink is associated with the channel. The invoke () method uses the messages sink to pass the message to the channel. Real proxy (proxy at the server) uses the message sink to pass the message into channel, so the sink can do some interception before the message goes into the channel.
  • Activator: Activator is used by the client to get proxy of a server- activate (already created) object.

Remoting

  • Configuration: Remote Configuration is used to configure servers and clients both dynamically or by using configuration files.
  • Channel Services: Channel Services are used to register channels and dispatch messages to them.

Client Side Working

When the client calls on a remote object, transparent proxy methods are called. Transparent proxy then calls the real proxy. The real proxy is responsible for sending the message to the channel. Real proxy in turn locates the message sink and passes the message to the sink. Message sink sends the message into the channel. Formatter formats the messages to be sent on wire. Channel is responsible for connecting to the listening socket on the server and sending the formatted data.

Server Side Working

Server channel receives the formatted messages and formatter un-marshals messages. Channel calls server-context sinks (message sinks associated with server), which in turn call object-context sinks (object sinks associated with an object). Last object-context sink calls the method in the remote object.

What is Context

An application domain can have different contexts. A context is used to group objects with similar execution requirements.

To bind an object to an application domain MarshalByRefObject is used. While ContextBoundObject which drives from MarshalByRefObject binds an object to context. Outside the context, proxy is needed to access the object.

Context attributes is assigned to objects derived from ContextBoundObject. Custom attribute can be created by implementing IContextAttribute.

Distributed applications components:

  1. Remote Objects
  2. Clients
  3. Servers

Remote Objects

An object that should be called remotely from a different system must be derived from System.MarshalByRefObject.

C#
Public class Hello:System.MarchalByRefObject
{
    Public Hello()
    {
    }
    ~Hello(){
    }

    Public string Greeting(string name)
    {
    }
}

The TCPServerChannel is created with some port to register it with Channel Services. Remote Object is then registered with RegisterWellKnownServiceType.

Client

In client program, we are creating TCPClientChannel to get the free port for communication. Activator is used to return a proxy to the remote object.

C#
Public class HelloClient
{
    Main()
    {
        ChannelServices.RegisterChannel ( new TCPClientChannel() );
        Hello obj = (Hello) Activator.GetObject(type of(Hello),
            "tcp://localhost:8086/Hi");
        If ( obj == null)
        {}
        for( int i=0; i < 5; i++) { obj.Greeting("");}
    } // end main
} // end HelloClient Class

History

  • 2nd January, 2008: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Pakistan Pakistan
I have been programming in different languages since 7 years which include C++, java, php and now C#.NET.

Comments and Discussions

 
QuestionLayout error? Pin
Member 312876811-Mar-08 22:50
Member 312876811-Mar-08 22:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.