サーバーでアクティブにできる既知の型として、クライアント エンドでオブジェクト Type を登録し、特定のパラメータを使用して WellKnownClientTypeEntry クラスの新しいインスタンスを初期化します。
Overloads Public Shared Sub RegisterWellKnownClientType( _
ByVal type As Type, _ ByVal objectUrl As String _)
[C#]
public static void RegisterWellKnownClientType(Typetype,stringobjectUrl);
[C++]
public: static void RegisterWellKnownClientType(Type* type,String* objectUrl);
[JScript]
public static function RegisterWellKnownClientType(
type : Type,objectUrl : String);
パラメータ
- type
オブジェクト Type 。 - objectUrl
既知のクライアント オブジェクトの URL。
例外
| 例外の種類 | 条件 |
|---|---|
| SecurityException | コールスタックの上位にある 1 つ以上の呼び出し元に、リモート処理の型とチャネルを構成するためのアクセス許可がありません。 |
解説
登録された既知のオブジェクトの URI を知っているすべてのクライアントは、 ChannelServices で優先するチャネルを登録し、New または Activator.GetObject を呼び出してそのオブジェクトをアクティブにすることにより、このオブジェクト用にプロキシを取得できます。New で既知のオブジェクトをアクティブにするには、初めに RegisterWellKnownClientType メソッドを使用して、その既知のオブジェクトの型をクライアント側で登録しておく必要があります。 RegisterWellKnownClientType メソッドを呼び出すと、リモート オブジェクトの場所がリモート処理インフラストラクチャに通知され、New キーワードでオブジェクトを作成できるようになります。一方、 Activator.GetObject メソッドを使用して、既知のオブジェクトをアクティブにする場合は、そのオブジェクトの URL を引数として指定する必要があります。このため、クライアント エンドでの事前の登録は必要ありません。
既知のオブジェクトの詳細については、「 サーバー アクティベーション 」を参照してください。
使用例
[Visual Basic, C#, C++] 既知の型としてクライアント エンドでオブジェクト型を登録する例を次に示します。ここで示すクライアント コードに対応するサーバー コードについては、 RegisterWellKnownServiceType メソッドのトピックの例を参照してください。
Imports System
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels.Tcp
Imports System.Runtime.Remoting.Channels
Public Class ClientClass
Public Shared Sub Main()
. . .
ChannelServices.RegisterChannel(New TcpChannel())
RemotingConfiguration.RegisterWellKnownClientType(GetType(HelloService), "tcp://localhost:8082/HelloServiceApplication/MyUri")
Dim service As New HelloService()
. . .
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.Tcp;
using System.Runtime.Remoting.Channels;
public class ClientClass {
public static void Main() {
. . .
ChannelServices.RegisterChannel(new TcpChannel());
RemotingConfiguration.RegisterWellKnownClientType(
typeof(HelloService),
"tcp://localhost:8082/HelloServiceApplication/MyUri"
);
HelloService service = new HelloService();
. . .
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::Tcp;
using namespace System::Runtime::Remoting::Channels;
int main()
{
. . .
ChannelServices::RegisterChannel(new TcpChannel());
RemotingConfiguration::RegisterWellKnownClientType(__typeof(HelloService),
S"tcp://localhost:8082/HelloServiceApplication/MyUri");
HelloService* service = new HelloService();
. . .
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.RegisterWellKnownClientType オーバーロードの一覧 | WellKnownClientTypeEntry | WellKnownServiceTypeEntry