I learnt today that I can create a proxy that intercepts calls to an object, do anything with the call and forward the call to the appropriate object. The same is true for the results. The whole thing is implemented by using a RealProxy implementation. I will demonstrate the functionality with .NET Remoting.
The common interface
public interface IServer
int Add(int a, int b);
The server implementation
class ServerImpl: MarshalByRefObject, IServer
#region IServer Members
public int Add(int a, int b)
return a + b;
public override object InitializeLifetimeService()
The server loop
static void Main()
// Windows Forms settings
// Remoting loop
RemotingServices.Marshal(new SzerverImplementacio(), "Server");
ChannelServices.RegisterChannel(new TcpChannel(8080), false);
// Windows Froms Window
The logging proxy
Call the server from the client
All the call end response properties will be listed in the Output window (or in the Console). The call will happen as there were no proxy class taking part in the call.
Apart Remoting this is a good solution for generating any kind of proxies:
- Virtual proxies
- Security proxies
RealProxy is a good extension point for an application.