次の方法で共有


リモート処理が可能な型の構築

クラスのインスタンスを他のアプリケーション ドメインのオブジェクトが使用できるようにするには、クラスを MarshalByRefObject から継承する必要があります。別のアプリケーション ドメインで実行されているオブジェクトによって作成され、使用される簡単なオブジェクトの例を次に示します。

' RemotableType.vb
Imports System

Public Class RemotableType
   Inherits MarshalByRefObject
   Private _internalString As String = "This is the RemotableType."
   
   Public Function StringMethod() As String
      Return _internalString
   End Function 'StringMethod
End Class 'RemotableType
[C#]
// RemotableType.cs
using System;
public class RemotableType : MarshalByRefObject{
  private string _internalString = "This is the RemotableType.";
  public string StringMethod(){
    return _internalString;
  }
}

この例のクラスは、MarshalByRefObject から継承したことを除き、すべての点で標準的です。.NET Framework SDK に含まれているコマンド ライン ツールでこのクラスをライブラリにコンパイルするには、これを RemotableType.language-extension という名前 (または別の任意の名前) で保存します。language-extension は、コンパイルする言語を示します。ファイルを保存したディレクトリのコマンド プロンプトで、次のコマンドを入力します。

[Visual Basic]

vbc /t:library RemotableType.vb

[C#]

csc /noconfig /t:library RemotableType.cs

このコマンドでは、ファイル名は次のとおりです。

[Visual Basic]

RemotableType.vb

[C#]

RemotableType.cs

参照

基本的な .NET リモート処理アプリケーションの構築 | 構成 | アクティベーション | MarshalByRefObject