特定の MarshalByRefObject を、指定した URI を持つ ObjRef クラスのインスタンスに変換します。
Overloads Public Shared Function Marshal( _
ByVal Obj As MarshalByRefObject, _ ByVal URI As String _) As ObjRef
[C#]
public static ObjRef Marshal(MarshalByRefObjectObj,stringURI);
[C++]
public: static ObjRef* Marshal(MarshalByRefObject* Obj,String* URI);
[JScript]
public static function Marshal(
Obj : MarshalByRefObject,URI : String) : ObjRef;
パラメータ
- Obj
変換対象のオブジェクト。 - URI
新しい ObjRef を初期化するために使用する指定した URI。 null 参照 (Visual Basic では Nothing) でもかまいません。
戻り値
Obj パラメータで指定されたオブジェクトを表している ObjRef クラスのインスタンス。
例外
例外の種類 | 条件 |
---|---|
RemotingException | Obj がオブジェクト プロキシであり、 URI パラメータが null 参照 (Visual Basic では Nothing) ではありません。 |
SecurityException | コールスタックの上位にある 1 つ以上の呼び出し元に、リモート処理の型とチャネルを構成するためのアクセス許可がありません。 |
解説
ObjRef は、アプリケーション ドメイン境界にわたってオブジェクト参照を転送するために使用するオブジェクトのシリアル化可能な表現です。オブジェクトの ObjRef を作成することをマーシャリングと言います。 ObjRef は、チャネルを経由して、別のプロセスやコンピュータ上にある場合もある別のアプリケーション ドメインに転送できます。他のアプリケーション ドメインに転送されたら、その ObjRef を解析して、通常は実際のオブジェクトに接続される、そのオブジェクトのプロキシを作成する必要があります。この操作は、マーシャリング解除として知られています。 ObjRef は、マーシャリング対象のオブジェクトの Type とクラスを説明する情報、特定のオブジェクト インスタンスを一意に識別する URI、およびオブジェクトが配置されているリモート処理サブ区分に到達する方法についての通信関連情報を格納します。
マーシャリング時には、オブジェクトが作成されたときにアクティブだったコンテキストではなく、現在のスレッドからのコンテキストが使用されます。
URI が、それ自体が表すオブジェクトに対してサーバー側で生成された場合や、URI が表すオブジェクトが既知の場合 (URI も既知になる) は、URI をプロキシに関連付けることはできません。このため、 Obj パラメータがプロキシである場合は、例外がスローされます。カスタム プロキシでは、透過プロキシがサーバー オブジェクトとして扱われるため、この制限は緩和されます。
使用例
[Visual Basic, C#, C++] 現在の Marshal メソッドを使用して、指定したオブジェクトをマーシャリングする方法の例を次に示します。
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] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
.NET Framework セキュリティ:
- SecurityPermission (リモート処理インフラストラクチャを構成するために必要なアクセス許可)要求値: SecurityAction.Demand; アクセス許可値: SecurityPermissionFlag.RemotingConfiguration
参照
RemotingServices クラス | RemotingServices メンバ | System.Runtime.Remoting 名前空間 | RemotingServices.Marshal オーバーロードの一覧 | Uri | アプリケーション ドメイン | RealProxy | ObjRef