サーバーでアクティブにできる型として、クライアント エンドでオブジェクト Type を登録し、特定のパラメータを使用して ActivatedClientTypeEntry クラスの新しいインスタンスを初期化します。
Overloads Public Shared Sub RegisterActivatedClientType( _
ByVal type As Type, _ ByVal appUrl As String _)
[C#]
public static void RegisterActivatedClientType(Typetype,stringappUrl);
[C++]
public: static void RegisterActivatedClientType(Type* type,String* appUrl);
[JScript]
public static function RegisterActivatedClientType(
type : Type,appUrl : String);
パラメータ
- type
オブジェクト Type 。 - appUrl
指定した型をアクティブにする側のアプリケーションの URL。
例外
| 例外の種類 | 条件 |
|---|---|
| ArgumentNullException | typeName パラメータまたは URI パラメータが null 参照 (Visual Basic では Nothing) です。 |
| SecurityException | コールスタックの上位にある 1 つ以上の呼び出し元に、リモート処理の型とチャネルを構成するためのアクセス許可がありません。 |
解説
サーバーでクライアント アクティブ化オブジェクトのインスタンスを作成するには、 Type を確認し、 RegisterActivatedServiceType メソッドを使用して、サーバー エンドで登録する必要があります。クライアント アクティブ化オブジェクトの新しいインスタンスのプロキシを取得するには、クライアントは最初にそのチャネルを ChannelServices で登録してから New を呼び出して、そのオブジェクトをアクティブにする必要があります。
クライアント アクティブ化オブジェクトの型を New キーワードを使用してアクティブにするには、初めに RegisterActivatedClientType メソッドを使用して、そのオブジェクトの型をクライアント側で登録しておく必要があります。 RegisterActivatedClientType メソッドを呼び出すと、New が作成しようとするリモート アプリケーションの場所がリモート処理インフラストラクチャに通知されます。一方、 Activator.CreateInstance メソッドを使用して、クライアント アクティブ化オブジェクトの新しいインスタンスを作成する場合は、リモート アプリケーションの URL をパラメータで指定する必要があります。このため、クライアント エンドでの事前の登録は必要ありません。 Activator.CreateInstance メソッドに、オブジェクトを作成するサーバーの URL を指定するには、 UrlAttribute クラスのインスタンスにその URL をカプセル化する必要があります。
クライアント アクティブ化オブジェクトの詳細については、「 クライアント アクティベーション 」を参照してください。
使用例
[Visual Basic, C#, C++] サーバーでアクティブにできる型としてクライアント エンドでオブジェクト型を登録する例を次に示します。ここで示すクライアント コードに対応するサーバー コードについては、 RegisterActivatedServiceType メソッドのトピックの例を参照してください。
Imports System
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp
Public Class ClientClass
Public Shared Sub Main()
ChannelServices.RegisterChannel(New TcpChannel())
RemotingConfiguration.RegisterActivatedClientType(GetType(HelloServiceClass), "tcp://localhost:8082")
Dim service As New HelloServiceClass()
If service Is Nothing Then
Console.WriteLine("Could not locate server.")
Return
End If
' Calls the remote method.
Console.WriteLine()
Console.WriteLine("Calling remote object")
Console.WriteLine(service.HelloMethod("Caveman"))
Console.WriteLine(service.HelloMethod("Spaceman"))
Console.WriteLine(service.HelloMethod("Client Man"))
Console.WriteLine("Finished remote object call")
Console.WriteLine()
End Sub 'Main
End Class 'ClientClass
[C#]
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
public class ClientClass {
public static void Main() {
ChannelServices.RegisterChannel(new TcpChannel());
RemotingConfiguration.RegisterActivatedClientType(typeof(HelloServiceClass),
"tcp://localhost:8082");
HelloServiceClass service = new HelloServiceClass();
if(service == null) {
Console.WriteLine("Could not locate server.");
return;
}
// Calls the remote method.
Console.WriteLine();
Console.WriteLine("Calling remote object");
Console.WriteLine(service.HelloMethod("Caveman"));
Console.WriteLine(service.HelloMethod("Spaceman"));
Console.WriteLine(service.HelloMethod("Client Man"));
Console.WriteLine("Finished remote object call");
Console.WriteLine();
}
}
[C++]
#using <mscorlib.dll>
#using <system.dll>
#using <system.runtime.remoting.dll>
using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Tcp;
int main()
{
ChannelServices::RegisterChannel(new TcpChannel());
RemotingConfiguration::RegisterActivatedClientType(__typeof(HelloServiceClass),
S"tcp://localhost:8082");
HelloServiceClass* service = new HelloServiceClass();
if (service == 0)
{
Console::WriteLine(S"Could not locate server.");
return -1;
}
// Calls the remote method.
Console::WriteLine();
Console::WriteLine(S"Calling remote Object");
Console::WriteLine(service->HelloMethod(S"Caveman"));
Console::WriteLine(service->HelloMethod(S"Spaceman"));
Console::WriteLine(service->HelloMethod(S"Client Man"));
Console::WriteLine(S"Finished remote Object call");
Console::WriteLine();
return 0;
}
[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
参照
RemotingConfiguration クラス | RemotingConfiguration メンバ | System.Runtime.Remoting 名前空間 | RemotingConfiguration.RegisterActivatedClientType オーバーロードの一覧 | ActivatedClientTypeEntry | ActivatedServiceTypeEntry