Editare

Partajați prin


RemotingServices.GetObjRefForProxy(MarshalByRefObject) Method

Definition

Returns the ObjRef that represents the remote object from the specified proxy.

public:
 static System::Runtime::Remoting::ObjRef ^ GetObjRefForProxy(MarshalByRefObject ^ obj);
public static System.Runtime.Remoting.ObjRef GetObjRefForProxy (MarshalByRefObject obj);
[System.Security.SecurityCritical]
public static System.Runtime.Remoting.ObjRef GetObjRefForProxy (MarshalByRefObject obj);
static member GetObjRefForProxy : MarshalByRefObject -> System.Runtime.Remoting.ObjRef
[<System.Security.SecurityCritical>]
static member GetObjRefForProxy : MarshalByRefObject -> System.Runtime.Remoting.ObjRef
Public Shared Function GetObjRefForProxy (obj As MarshalByRefObject) As ObjRef

Parameters

obj
MarshalByRefObject

A proxy connected to the object you want to create a ObjRef for.

Returns

A ObjRef that represents the remote object the specified proxy is connected to, or null if the object or proxy have not been marshaled.

Attributes

Exceptions

The immediate caller does not have infrastructure permission.

Examples

The following code example demonstrates how to get a ObjRef instance for the specified object.

ObjRef^ objRefSample = RemotingServices::GetObjRefForProxy( myRemoteObject );
Console::WriteLine( "***ObjRef Details***" );
Console::WriteLine( "URI:\t {0}", objRefSample->URI );
array<Object^>^channelData = objRefSample->ChannelInfo->ChannelData;
Console::WriteLine( "Channel Info:" );
IEnumerator^ myEnum = channelData->GetEnumerator();
while ( myEnum->MoveNext() )
{
   Object^ o = safe_cast<Object^>(myEnum->Current);
   Console::WriteLine( "\t {0}", o );
}

IEnvoyInfo^ envoyInfo = objRefSample->EnvoyInfo;
if ( envoyInfo == nullptr )
{
   Console::WriteLine( "This ObjRef does not have envoy information." );
}
else
{
   IMessageSink^ envoySinks = envoyInfo->EnvoySinks;
   Console::WriteLine( "Envoy Sink Class: {0}", envoySinks );
}

IRemotingTypeInfo^ typeInfo = objRefSample->TypeInfo;
Console::WriteLine( "Remote type name: {0}", typeInfo->TypeName );
Console::WriteLine( "Can my Object* cast to a Bitmap? {0}", typeInfo->CanCastTo( System::Drawing::Bitmap::typeid, objRefSample ) );
ObjRef objRefSample = RemotingServices.GetObjRefForProxy(myRemoteObject);

Console.WriteLine("***ObjRef Details***");
Console.WriteLine("URI:\t{0}", objRefSample.URI);

object[] channelData = objRefSample.ChannelInfo.ChannelData;

Console.WriteLine("Channel Info:");
foreach(object o in channelData)
    Console.WriteLine("\t{0}", o.ToString());

IEnvoyInfo envoyInfo = objRefSample.EnvoyInfo;

if (envoyInfo == null) {
    Console.WriteLine("This ObjRef does not have envoy information.");
}
else {
    IMessageSink envoySinks = envoyInfo.EnvoySinks;
    Console.WriteLine("Envoy Sink Class: {0}", envoySinks);
}

IRemotingTypeInfo typeInfo = objRefSample.TypeInfo;
Console.WriteLine("Remote type name: {0}", typeInfo.TypeName);

Console.WriteLine("Can my object cast to a Bitmap? {0}",
    typeInfo.CanCastTo(typeof(System.Drawing.Bitmap), objRefSample));
Dim objRefSample As ObjRef = RemotingServices.GetObjRefForProxy(myRemoteObject)

Console.WriteLine("***ObjRef Details***")
Console.WriteLine("URI:" + ControlChars.Tab + "{0}", objRefSample.URI)

Dim channelData As Object() = objRefSample.ChannelInfo.ChannelData
Console.WriteLine("Channel Info:")

Dim o As Object
For Each o In  channelData
   Console.WriteLine(ControlChars.Tab + "{0}", o.ToString())
Next o

Dim envoyInfo As IEnvoyInfo = objRefSample.EnvoyInfo
If envoyInfo Is Nothing Then
   Console.WriteLine("This ObjRef does not have envoy information.")
Else
   Dim envoySinks As IMessageSink = envoyInfo.EnvoySinks
   Console.WriteLine("Envoy Sink Class: {0}", envoySinks)
End If

Dim typeInfo As IRemotingTypeInfo = objRefSample.TypeInfo
Console.WriteLine("Remote type name: {0}", typeInfo.TypeName)

Console.WriteLine("Can my object cast to a Bitmap? {0}", typeInfo.CanCastTo(GetType(System.Drawing.Bitmap), objRefSample))

Remarks

A ObjRef is a serializable representation of an object used to transfer an object reference across an application domain boundary. Creating a ObjRef for an object is known as marshaling. The ObjRef can be transferred through a channel into another application domain (possibly on another process or computer). Once in the other application domain, the ObjRef must be parsed to create a proxy for the object, generally connected to the real object. This operation is known as unmarshaling. During unmarshaling, the ObjRef is parsed to extract the method information of the remote object and both the transparent proxy and RealProxy objects are created.

A ObjRef contains information that describes the Type and class of the object being marshaled, a URI that uniquely identifies the specific object instance, and communication related information about how to reach the remote application where the object is located.

Applies to