[Serializable] |
The ObjRef contains information that describes the Type and class of the object being marshaled, its exact location, and communication-related information on how to reach the remoting subdivision where the object is located.
After a class implementing MarshalByRefObject is marshaled, the ObjRef that represents it is transferred through a channel into another AppDomain, possibly in another process or computer. When the ObjRef is deserialized (see the conceptual topic at MSDN: serialization) in the target AppDomain, it is parsed to create a transparent proxy for the remote MBR object. This operation is known as unmarshaling.
A transparent proxy is an object that provides the illusion that the actual object resides in the client's space. It achieves this by forwarding calls made on it to the real object using the remoting infrastructure. The transparent proxy is itself housed by an instance of a managed run-time class of type RealProxy. The RealProxy implements a part of the functionality needed to forward the operations from the transparent proxy.
A proxy object can be used without regard to any remoting subdivisions within an AppDomain. Applications need not distinguish between proxy references and object references. However, service providers dealing with issues such as activation, lifetime management, and transactions need to make such distinctions.
// a custom ObjRef class that outputs its status public class MyObjRef : ObjRef { // only instantiate via marshaling or deserialization private MyObjRef() { } public MyObjRef(MarshalByRefObject o, Type t) : base(o, t) { Console.WriteLine("Created MyObjRef."); ORDump(); } public MyObjRef(SerializationInfo i, StreamingContext c) : base(i, c) { Console.WriteLine("Deserialized MyObjRef."); } public override void GetObjectData(SerializationInfo s, StreamingContext c) { // After calling the base method, change the type from ObjRef to MyObjRef base.GetObjectData(s, c); s.SetType(GetType()); Console.WriteLine("Serialized MyObjRef."); } public override Object GetRealObject(StreamingContext context) { if ( IsFromThisAppDomain() || IsFromThisProcess() ) { Console.WriteLine("Returning actual object referenced by MyObjRef."); return base.GetRealObject(context); } else { Console.WriteLine("Returning proxy to remote object."); return RemotingServices.Unmarshal(this); } } public void ORDump() { Console.WriteLine(" --- Reporting MyObjRef Info --- "); Console.WriteLine("Reference to {0}.", TypeInfo.TypeName); Console.WriteLine("URI is {0}.", URI); Console.WriteLine("\nWriting EnvoyInfo: "); if ( EnvoyInfo != null) { IMessageSink EISinks = EnvoyInfo.EnvoySinks; while (EISinks != null) { Console.WriteLine("\tSink: " + EISinks.ToString()); EISinks = EISinks.NextSink; } } else Console.WriteLine("\t {no sinks}"); Console.WriteLine("\nWriting ChannelInfo: "); for (int i = 0; i < ChannelInfo.ChannelData.Length; i++) Console.WriteLine ("\tChannel: {0}", ChannelInfo.ChannelData[i]); Console.WriteLine(" ----------------------------- "); } } // a class that uses MyObjRef public class LocalObject : MarshalByRefObject { // overriding CreateObjRef will allow us to return a custom ObjRef public override ObjRef CreateObjRef(Type t) { return new MyObjRef(this, t); } }
ctor #1 | Overloaded:.ctor() Default constructor. This constructor is called by derived class constructors to initialize state in this type.Initializes a new instance of the ObjRef class with default values. |
ctor #2 | Overloaded:.ctor(MarshalByRefObject o, Type requestedType) Initializes a new instance of the ObjRef class to reference a specified MarshalByRefObject of a specified Type. |
ChannelInfo | Read-write Gets or sets the IChannelInfo for the ObjRef. |
EnvoyInfo | Read-write Gets or sets the IEnvoyInfo for the ObjRef. |
TypeInfo | Read-write Gets or sets the IRemotingTypeInfo for the object that the ObjRef describes. |
URI | Read-write Gets or sets the URI of the specific object instance. |
Equals (inherited from System.Object) |
See base class member description: System.Object.Equals Derived from System.Object, the primary base class for all objects. |
GetHashCode (inherited from System.Object) |
See base class member description: System.Object.GetHashCode Derived from System.Object, the primary base class for all objects. |
GetObjectData | Populates a specified SerializationInfo with the data needed to serialize the current ObjRef instance. |
GetRealObject | Returns a reference to the remote object that the ObjRef describes. |
GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
IsFromThisAppDomain | Returns a Boolean value indicating whether the current ObjRef instance references an object located in the current AppDomain. |
IsFromThisProcess | Returns a Boolean value indicating whether the current ObjRef instance references an object located in the current process. |
ToString (inherited from System.Object) |
See base class member description: System.Object.ToString Derived from System.Object, the primary base class for all objects. |
ctor #3 | Overloaded:.ctor(SerializationInfo info, StreamingContext context) Initializes a new instance of the ObjRef class from serialized data. |
Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
public ObjRef(); |
public ObjRef( |
o
requestedType
protected ObjRef( |
info
context
public virtual IChannelInfo ChannelInfo {get; set;}
|
public virtual IEnvoyInfo EnvoyInfo {get; set;}
|
public virtual IRemotingTypeInfo TypeInfo {get; set;}
|
public virtual string URI {get; set;}
|
~ObjRef(); |
public virtual int GetHashCode(); |
public virtual void GetObjectData( |
info
context
Exception Type | Condition |
---|---|
ArgumentNullException | The info parameter is null. |
The current method is an implementation of ISerializable.GetObjectData.
public virtual object GetRealObject( |
context
public Type GetType(); |
public bool IsFromThisAppDomain(); |
public bool IsFromThisProcess(); |
protected object MemberwiseClone(); |
public virtual string ToString(); |