Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

RemotingServices.Marshal Method (MarshalByRefObject, String)

.NET Framework 1.1

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

[Visual Basic]
Overloads Public Shared Function Marshal( _
   ByVal Obj As MarshalByRefObject, _
   ByVal URI As String _
) As ObjRef
[C#]
public static ObjRef Marshal(
 MarshalByRefObject Obj,
 string URI
);
[C++]
public: static ObjRef* Marshal(
 MarshalByRefObject* Obj,
 String* URI
);
[JScript]
public static function Marshal(
   Obj : MarshalByRefObject,
 URI : String
) : ObjRef;

Parameters

Obj
The object to convert.
URI
The specified URI with which to initialize the new ObjRef. Can be a null reference (Nothing in Visual Basic).

Return Value

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

Exceptions

Exception Type Condition
RemotingException Obj is an object proxy, and the URI parameter is not a null reference (Nothing in Visual Basic).
SecurityException At least one of the callers higher in the callstack does not have permission to configure remoting types and channels.

Remarks

An ObjRef is a serializable representation of an object used to transfer an object reference across an AppDomain boundary. Creating an ObjRef for an object is known as marshaling. The ObjRef can be transferred through a channel into another AppDomain (possibly on another process or computer). 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 known as unmarshaling. ObjRef s contain 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 on 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.

Example

[Visual Basic, C#, C++] The following example demonstrates how to use the current Marshal method to marshal a specified object.

[Visual Basic] 
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()

[C#] 
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();

[C++] 
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, S"objectWellKnownUri");
Console::WriteLine(S"An instance of SampleWellKnown type is published at {0}.", objrefWellKnown->URI);

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

Console::WriteLine(S"Press enter to end the server process.");
Console::ReadLine();

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

RemotingServices Class | RemotingServices Members | System.Runtime.Remoting Namespace | RemotingServices.Marshal Overload List | Uri | Application Domains | RealProxy | ObjRef

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.