Muokkaa

Jaa


RemotingServices.Marshal Method

Definition

Converts the given MarshalByRefObject into an instance of the ObjRef class, which can be serialized for transmission between application domains and over a network.

Overloads

Marshal(MarshalByRefObject)

Takes a MarshalByRefObject, registers it with the remoting infrastructure, and converts it into an instance of the ObjRef class.

Marshal(MarshalByRefObject, String)

Converts the given MarshalByRefObject into an instance of the ObjRef class with the specified URI.

Marshal(MarshalByRefObject, String, Type)

Takes a MarshalByRefObject and converts it into an instance of the ObjRef class with the specified URI, and the provided Type.

Marshal(MarshalByRefObject)

Takes a MarshalByRefObject, registers it with the remoting infrastructure, and converts it into an instance of the ObjRef class.

public:
 static System::Runtime::Remoting::ObjRef ^ Marshal(MarshalByRefObject ^ Obj);
public static System.Runtime.Remoting.ObjRef Marshal (MarshalByRefObject Obj);
static member Marshal : MarshalByRefObject -> System.Runtime.Remoting.ObjRef
Public Shared Function Marshal (Obj As MarshalByRefObject) As ObjRef

Parameters

Obj
MarshalByRefObject

The object to convert.

Returns

An instance of the ObjRef class that represents the object specified in the Obj parameter.

Exceptions

The Obj parameter is an object proxy.

At least one of the callers higher in the callstack does not have permission to configure remoting types and channels.

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.

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 remoting subdivision where the object is located.

During marshaling, the context from the current thread is used, not the context that was active when the object was created. If a URI was not explicitly set by the SetObjectUriForMarshal method, it is automatically generated by the remoting identity infrastructure.

You cannot associate a URI with a proxy for one of two reasons: either the URI was generated at the server side for the object it represents, or the object is well known, in which case the URI is known. For this reason, if the Obj parameter is a proxy, an exception will be thrown. For custom proxies this restriction is relaxed because the transparent proxy is treated as the server object.

See also

Applies to

Marshal(MarshalByRefObject, String)

Converts the given MarshalByRefObject into an instance of the ObjRef class with the specified URI.

public:
 static System::Runtime::Remoting::ObjRef ^ Marshal(MarshalByRefObject ^ Obj, System::String ^ URI);
public static System.Runtime.Remoting.ObjRef Marshal (MarshalByRefObject Obj, string URI);
static member Marshal : MarshalByRefObject * string -> System.Runtime.Remoting.ObjRef
Public Shared Function Marshal (Obj As MarshalByRefObject, URI As String) As ObjRef

Parameters

Obj
MarshalByRefObject

The object to convert.

URI
String

The specified URI with which to initialize the new ObjRef. Can be null.

Returns

An instance of the ObjRef class that represents the object specified in the Obj parameter.

Exceptions

Obj is an object proxy, and the URI parameter is not null.

At least one of the callers higher in the callstack does not have permission to configure remoting types and channels.

Examples

The following code example demonstrates how to use the current Marshal method to marshal a specified object.

TcpChannel^ channel = gcnew TcpChannel( 9000 );
ChannelServices::RegisterChannel( channel );
SampleWellKnown ^ objectWellKnown = gcnew SampleWellKnown;

// After the channel is registered, the Object* needs to be registered
// with the remoting infrastructure.  So, Marshal is called.
ObjRef^ objrefWellKnown = RemotingServices::Marshal( objectWellKnown, "objectWellKnownUri" );
Console::WriteLine( "An instance of SampleWellKnown type is published at {0}.", objrefWellKnown->URI );
Console::WriteLine( "Press enter to unregister SampleWellKnown, so that it is no longer available on this channel." );
Console::ReadLine();
RemotingServices::Disconnect( objectWellKnown );
Console::WriteLine( "Press enter to end the server process." );
Console::ReadLine();
TcpChannel channel = new TcpChannel(9000);
ChannelServices.RegisterChannel(channel);

SampleWellKnown objectWellKnown = new SampleWellKnown();

// After the channel is registered, the object needs to be registered
// with the remoting infrastructure.  So, Marshal is called.
ObjRef objrefWellKnown = RemotingServices.Marshal(objectWellKnown, "objectWellKnownUri");
Console.WriteLine("An instance of SampleWellKnown type is published at {0}.", objrefWellKnown.URI);

Console.WriteLine("Press enter to unregister SampleWellKnown, so that it is no longer available on this channel.");
Console.ReadLine();
RemotingServices.Disconnect(objectWellKnown);

Console.WriteLine("Press enter to end the server process.");
Console.ReadLine();
Dim channel As New TcpChannel(9000)
ChannelServices.RegisterChannel(channel)

Dim objectWellKnown As New SampleWellKnown()
' After the channel is registered, the object needs to be registered
' with the remoting infrastructure.  So, Marshal is called.
Dim objrefWellKnown As ObjRef = RemotingServices.Marshal(objectWellKnown, "objectWellKnownUri")
Console.WriteLine("An instance of SampleWellKnown type is published at {0}.", objrefWellKnown.URI)

Console.WriteLine("Press enter to unregister SampleWellKnown, so that it is no longer available on this channel.")
Console.ReadLine()
RemotingServices.Disconnect(objectWellKnown)
Console.WriteLine("Press enter to end the server process.")
Console.ReadLine()

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.

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 remoting subdivision where the object is located.

During marshaling, the context from the current thread is used, not the context that was active when the object was created.

You cannot associate a URI with a proxy for one of two reasons: either the URI was generated at the server side for the object it represents, or the object is well known, in which case the URI is known. For this reason, if the Obj parameter is a proxy, an exception will be thrown. For custom proxies this restriction is relaxed because the transparent proxy is treated as the server object.

See also

Applies to

Marshal(MarshalByRefObject, String, Type)

Takes a MarshalByRefObject and converts it into an instance of the ObjRef class with the specified URI, and the provided Type.

public:
 static System::Runtime::Remoting::ObjRef ^ Marshal(MarshalByRefObject ^ Obj, System::String ^ ObjURI, Type ^ RequestedType);
public static System.Runtime.Remoting.ObjRef Marshal (MarshalByRefObject Obj, string ObjURI, Type RequestedType);
static member Marshal : MarshalByRefObject * string * Type -> System.Runtime.Remoting.ObjRef
Public Shared Function Marshal (Obj As MarshalByRefObject, ObjURI As String, RequestedType As Type) As ObjRef

Parameters

Obj
MarshalByRefObject

The object to convert into a ObjRef.

ObjURI
String

The URI the object specified in the Obj parameter is marshaled with. Can be null.

RequestedType
Type

The TypeObj is marshaled as. Can be null.

Returns

An instance of the ObjRef class that represents the object specified in the Obj parameter.

Exceptions

Obj is a proxy of a remote object, and the ObjUri parameter is not null.

At least one of the callers higher in the callstack does not have permission to configure remoting types and channels.

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.

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 remoting subdivision where the object is located.

The specified Type is used by the remoting infrastructure to limit the scope of the exposed type hierarchy. For example, if object A derives from object B, which derives from object C, and Marshal is called, then the client can cast the proxy between C and B but not to A.

During marshaling, the context from the current thread is used, not the context that was active when the object was created.

You cannot associate a URI with a proxy for one of two reasons: either the URI was generated at the server side for the object it represents, or the object is well known, in which case the URI is known. For this reason, if the Obj parameter is a proxy, an exception will be thrown. For custom proxies this restriction is relaxed because the transparent proxy is treated as the server object.

See also

Applies to