方法 : リモート処理が可能な型を構築する
このトピックの対象は、既存のアプリケーションとの下位互換性のために残されているレガシ テクノロジに特定されています。新規の開発には、このトピックを適用しないでください。分散アプリケーションは、現在は Windows Communication Foundation (WCF) を使用して開発する必要があります。
他のアプリケーション ドメインのオブジェクトがクラスのインスタンスを使用できるようにするには、クラスを MarshalByRefObject から継承する必要があります。次の手順は、別のアプリケーション ドメインで実行されているオブジェクトによって作成したり、呼び出したりできる基本的なオブジェクトの作成方法を示しています。
注 : |
---|
このサンプル コードをビルドして実行する方法の詳細な説明については、「方法 : 基本的なリモート処理アプリケーションをコンパイルして実行する」を参照してください。 |
リモート処理が可能な型を構築するには
MarshalByRefObject クラスから派生するクラスを定義します。
Public Class RemotableType Inherits MarshalByRefObject … End Class
public class RemotableType : MarshalByRefObject { … }
リモート処理が可能でない型の場合と同様に、クラスのメソッドとプロパティを実装します。文字列がリスナーで表示されるように、
Console.WriteLine
を呼び出します。これは、後でリモート オブジェクトが呼び出されたことを示すために使用します。Public Function SayHello() As String Console.WriteLine("RemotableType.SayHello() was called!") Return "Hello, world" End Function 'StringMethod
public string SayHello(){ Console.WriteLine("RemotableType.SayHello() was called!"); return "Hello, world"; }
remoting\type
という名前のディレクトリを作成し、クラスをRemotableType.cs
またはRemotingType.vb
として新しいディレクトリに保存します。コマンド プロンプトを開き、remoting\type
ディレクトリに移動して、次のコマンドを入力します。vbc /t:library RemotableType.vb
csc /noconfig /t:library RemotableType.cs
例
' RemotableType.vb
Imports System
Public Class RemotableType
Inherits MarshalByRefObject
Public Function SayHello() As String
Console.WriteLine("RemotableType.SayHello() was called!")
Return "Hello, world"
End Function
End Class
// RemotableType.cs
using System;
public class RemotableType : MarshalByRefObject
{
public string SayHello()
{
Console.WriteLine("RemotableType.SayHello() was called!");
return "Hello, world";
}
}
参照
処理手順
方法 : ホスト アプリケーションを構築する
方法 : クライアント アプリケーションを構築する
リファレンス
概念
リモート アプリケーションの構成
サーバー アクティベーション
その他のリソース
基本的な .NET Framework リモート処理アプリケーションの構築
ビルド日:2010-02-13