An ObjRef is a serializable representation of an object used to transfer an object reference across an AppDomain boundary. The act of creating an ObjRef for an object is called marshaling. The ObjRef can be transferred via a channel into another AppDomain (possibly on another process or machine). Once in the other AppDomain, the ObjRef must be parsed to create a Proxy for the Object, generally connected to the real Object. This operation is called unmarshaling. ObjRefs have enough information that describes the Type / class of the object being marshaled (like the class hierarchy), something that will uniquely identify the specific object instance (the URI) and how to reach the remoting-subdivision where the object lives (communication related information).
An important notion to be aware of about marshaling are the semantics of Marshal-by-Value versus Marshal-by-Reference. When a reference to an Object is converted to an ObjRef such that the Proxy created after unmarshaling talks to the original object for most method calls via a proxy, this is called Marshal-by-Reference. However, there are objects whose state does not change in any interesting way once initialized. For such objects, it makes sense to send over the entire state of the Object in the ObjRef and then create a local object that is a clone of the remote one within the remoting-boundary of the client. This is called Marshal-by-Value.
Defines the marshaled object reference class and related classes
public class ObjRef : public IObjectReference { public: //Constructors public ObjRef (); public IChannelInfo ChannelInfo {get; set;}; public IEnvoyInfo EnvoyInfo {get; set;}; public IRemotingTypeInfo TypeInfo {get; set;}; public virtual Object GetRealObject (StreamingContext context); public String URI {get;set}; };
This read-write property returns the IChannelInfo interface for the ObjRef. Channels are described in further detail in the channels section.
This read-write property returns the IEnvoyInfo interface for the ObjRef. Envoys are described in further detail in the contexts section.
This read-write property returns the IRemotingTypeInfo for the objRef. TypeInfo is utilized to refine the proxy to suit the client view of the server object.
This read-write property uniquely represents the identity of the specific object instance.
Interface for providing channel information. Users can use this interface to provide custom channel information which is carried along with the ObjRef.
public interface IChannelInfo { Object[] ChannelData {get; set;} String[] ChannelNames {get; set;} }
This read-write property gets/sets the channel data for each channel.
This read-write property gets/sets the names of the channels.
Provides envoy information. Users can use this interface to provide custom envoy information which is carried along with the ObjRef.
public interface IEnvoyInfo { IMessageSink EnvoySinks {get; set;}; }
This read-write property gets/sets the envoy sinks. The list of envoys which were contributed by the ServerContext and ServerObject chains when the Object was marshaled.
Interface for providing type information. Users can use this interface to provide custom type information which is carried along with the ObjRef.
public interface IRemotingTypeInfo { String TypeName { get; set; } bool CanCastTo(Type fromType, Object o); }
This read-write property returns the fully qualified type name.
Check whether the given type can be cast to the requested type.