RemotingServices::Marshal Method (MarshalByRefObject, String)
Converts the given MarshalByRefObject into an instance of the ObjRef class with the specified URI.
Assembly: mscorlib (in mscorlib.dll)
[SecurityPermissionAttribute(SecurityAction::Demand, Flags = SecurityPermissionFlag::RemotingConfiguration)] public: static ObjRef^ Marshal( MarshalByRefObject^ Obj, String^ URI )
Parameters
- Obj
- Type: System::MarshalByRefObject
The object to convert.
- URI
- Type: System::String
The specified URI with which to initialize the new ObjRef. Can be nullptr.
Return Value
Type: System.Runtime.Remoting::ObjRefAn instance of the ObjRef class that represents the object specified in the Obj parameter.
| Exception | Condition |
|---|---|
| RemotingException | Obj is an object proxy, and the URI parameter is not nullptr. |
| SecurityException | At least one of the callers higher in the callstack does not have permission to configure remoting types and channels. |
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.
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();
- SecurityPermission
for configuration of the remoting infrastructure. Demand value: SecurityAction::Demand; Permission value: SecurityPermissionFlag::RemotingConfiguration
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.