ASP.NET: Marshalling


In the process of marshalling the objects are packed in to message buffer before transmitted as the objects can't be transmitted over communication channel. There are two different ways to Marshal objects. In other words "Marshalling" is used when an object is converted so that it can be sent across the network or across application domains.
 

Marshal by Value: Server creates copy of the remoting object's state and passes it to the client. You need to implement your classes to have marshal by value features either by implementing ISerializable interface or using attribute. Here you need to copy whole object to the client which means with large size object, the communication overhead is significant.

Marshal by Reference:
In this type proxy is created by the reference of the server objects. Class must extend the System.MarshalByRefObject to implement marshal by reference. Here, client keeps server object reference which means round trip to server with each method call. 

To marshal a remote object the static method RemotingServices.Marshal() is used which has following overloaded versions:-

public static ObjRef Marshal(MarshalByRefObject obj)
public static ObjRef Marshal(MarshalByRefObject obj, string objUri)
public static ObjRef Marshal(MarshalByRefObject obj, string objUri,Type requestedType)
Next Recommended Reading ASP.NET Authorization