RemotingServices.Marshal 方法

定義

轉換指定的 MarshalByRefObjectObjRef 類別的執行個體,這個執行個體可以序列化,以在應用程式定義域之間和在網路上進行傳輸。

多載

Marshal(MarshalByRefObject)

取得 MarshalByRefObject,使用遠端基礎架構進行登錄,並且將它轉換為 ObjRef 類別的執行個體。

Marshal(MarshalByRefObject, String)

將指定的 MarshalByRefObject 轉換為具有指定 URI 的 ObjRef 類別執行個體。

Marshal(MarshalByRefObject, String, Type)

取得 MarshalByRefObject,並且將它轉換為具有指定 URI 和所提供 ObjRefType 類別的執行個體。

Marshal(MarshalByRefObject)

取得 MarshalByRefObject,使用遠端基礎架構進行登錄,並且將它轉換為 ObjRef 類別的執行個體。

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

參數

Obj
MarshalByRefObject

要轉換的物件。

傳回

ObjRef 類別的執行個體,表示 Obj 參數中指定的物件。

例外狀況

Obj 參數是物件 Proxy。

至少有一個呼叫堆疊中較高的呼叫端,不具有設定遠端類型和通道的使用權限。

備註

ObjRef是物件可串行化的表示法,用來跨應用程式域界限傳輸對象參考。 ObjRef建立對象的 稱為封送處理。 ObjRef可以透過通道傳輸到另一個應用程式域, (可能在另一個進程或計算機上) 。 在其他應用程式域中, ObjRef 必須剖析 ,才能為物件建立 Proxy,通常連接到實際物件。 這項作業稱為「取消封擷取」。

ObjRef包含可描述Type要封送處理之物件的 和類別、可唯一識別特定物件實例的 URI,以及如何連線到物件所在遠端細分的相關信息。

在封送處理期間,會使用來自目前線程的內容,而不是建立物件時作用中的內容。 如果方法未明確設定 SetObjectUriForMarshal URI,則會由遠端識別基礎結構自動產生。

您無法基於下列兩個原因之一,將 URI 與 Proxy 產生:URI 是在伺服器端針對它所代表的物件產生,或物件已知,在此情況下,URI 是已知的。 基於這個理由,如果 Obj 參數是 Proxy,將會擲回例外狀況。 對於自定義 Proxy,這項限制會寬鬆,因為透明 Proxy 會被視為伺服器物件。

另請參閱

適用於

Marshal(MarshalByRefObject, String)

將指定的 MarshalByRefObject 轉換為具有指定 URI 的 ObjRef 類別執行個體。

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

參數

Obj
MarshalByRefObject

要轉換的物件。

URI
String

指定的 URI,用來初始化新的 ObjRef。 可以是 null

傳回

ObjRef 類別的執行個體,表示 Obj 參數中指定的物件。

例外狀況

Obj 為物件 Proxy,並且 URI 參數不是 null

至少有一個呼叫堆疊中較高的呼叫端,不具有設定遠端類型和通道的使用權限。

範例

下列程式代碼範例示範如何使用目前的 Marshal 方法來封送處理指定的物件。

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()

備註

ObjRef是物件可串行化的表示法,用來跨應用程式域界限傳輸對象參考。 ObjRef建立對象的 稱為封送處理。 ObjRef可以透過通道傳輸到另一個應用程式域, (可能在另一個進程或計算機上) 。 在其他應用程式域中, ObjRef 必須剖析 ,才能為物件建立 Proxy,通常連接到實際物件。 這項作業稱為「取消封擷取」。

ObjRef包含可描述Type要封送處理之物件的 和類別、可唯一識別特定物件實例的 URI,以及如何連線到物件所在遠端細分的相關信息。

在封送處理期間,會使用來自目前線程的內容,而不是建立物件時作用中的內容。

您無法基於下列兩個原因之一,將 URI 與 Proxy 產生:URI 是在伺服器端針對它所代表的物件產生,或物件已知,在此情況下,URI 是已知的。 基於這個理由,如果 Obj 參數是 Proxy,將會擲回例外狀況。 對於自定義 Proxy,這項限制會寬鬆,因為透明 Proxy 會被視為伺服器物件。

另請參閱

適用於

Marshal(MarshalByRefObject, String, Type)

取得 MarshalByRefObject,並且將它轉換為具有指定 URI 和所提供 ObjRefType 類別的執行個體。

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

參數

Obj
MarshalByRefObject

要轉換為 ObjRef 的物件。

ObjURI
String

用來封送處理 Obj 參數中所指定物件的 URI。 可以是 null

RequestedType
Type

封送處理成的 TypeObj。 可以是 null

傳回

ObjRef 類別的執行個體,表示 Obj 參數中指定的物件。

例外狀況

Obj 為遠端物件的 Proxy,而且 ObjUri 參數不是 null

至少有一個呼叫堆疊中較高的呼叫端,不具有設定遠端類型和通道的使用權限。

備註

ObjRef是物件可串行化的表示法,用來跨應用程式域界限傳輸對象參考。 ObjRef建立對象的 稱為封送處理。 ObjRef可以透過通道傳輸到另一個應用程式域, (可能在另一個進程或計算機上) 。 在其他應用程式域中, ObjRef 必須剖析 ,才能為物件建立 Proxy,通常連接到實際物件。 這項作業稱為「取消封擷取」。

ObjRef包含可描述Type要封送處理之物件的 和類別、可唯一識別特定物件實例的 URI,以及如何連線到物件所在遠端細分的相關信息。

指定的 Type 是由遠端基礎結構用來限制公開類型階層的範圍。 例如,如果物件 A 衍生自物件 B,其衍生自物件 C,而且 Marshal 被呼叫,則用戶端可以在 C 和 B 之間轉換 Proxy,但不能轉換成 A。

在封送處理期間,會使用來自目前線程的內容,而不是建立物件時作用中的內容。

您無法基於下列兩個原因之一,將 URI 與 Proxy 產生:URI 是在伺服器端針對它所代表的物件產生,或物件已知,在此情況下,URI 是已知的。 基於這個理由,如果 Obj 參數是 Proxy,將會擲回例外狀況。 對於自定義 Proxy,這項限制會寬鬆,因為透明 Proxy 會被視為伺服器物件。

另請參閱

適用於