RemotingConfiguration.RegisterActivatedClientType 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在用戶端註冊 Type 一個物件,作為可在伺服器上啟用的類型。
多載
| 名稱 | Description |
|---|---|
| RegisterActivatedClientType(ActivatedClientTypeEntry) |
在用戶端註冊一個可在伺服器端啟用的物件TypeActivatedClientTypeEntry類型。 |
| RegisterActivatedClientType(Type, String) |
在用戶端註冊 Type 一個物件,作為一個可於伺服器啟動的型別,並利用給定參數初始化該 ActivatedClientTypeEntry 類別的新實例。 |
RegisterActivatedClientType(ActivatedClientTypeEntry)
在用戶端註冊一個可在伺服器端啟用的物件TypeActivatedClientTypeEntry類型。
public:
static void RegisterActivatedClientType(System::Runtime::Remoting::ActivatedClientTypeEntry ^ entry);
public static void RegisterActivatedClientType(System.Runtime.Remoting.ActivatedClientTypeEntry entry);
static member RegisterActivatedClientType : System.Runtime.Remoting.ActivatedClientTypeEntry -> unit
Public Shared Sub RegisterActivatedClientType (entry As ActivatedClientTypeEntry)
參數
- entry
- ActivatedClientTypeEntry
用戶端啟用類型的設定。
例外狀況
呼叫堆疊中至少有一個呼叫者沒有權限設定遠端存取類型和通道。
備註
要在伺服器端建立由客戶端啟動的物件實例,你必須知道它 Type ,並且必須透過此 RegisterActivatedServiceType 方法在伺服器端註冊。 要取得用戶端啟用物件新實例的代理,用戶端必須先註冊一個通道, ChannelServices 然後透過呼叫 new來啟動該物件。
要啟用由客戶端啟用的物件類型,並使用 new 關鍵字,您必須先在用戶端使用該 RegisterActivatedClientType 方法註冊該物件類型。 呼叫該 RegisterActivatedClientType 方法會讓遠端基礎設施知道遠端應用程式的位置,並 new 嘗試建立該應用程式。 反之,若你使用此 Activator.CreateInstance 方法建立客戶端啟用物件的新實例,必須提供遠端應用程式的 URL 作為參數,因此客戶端無需事先註冊。 若要提供 Activator.CreateInstance 該方法並提供你想建立物件的伺服器 URL,你必須將該 URL 封裝在該類別的 UrlAttribute 實例中。
另請參閱
適用於
RegisterActivatedClientType(Type, String)
在用戶端註冊 Type 一個物件,作為一個可於伺服器啟動的型別,並利用給定參數初始化該 ActivatedClientTypeEntry 類別的新實例。
public:
static void RegisterActivatedClientType(Type ^ type, System::String ^ appUrl);
public static void RegisterActivatedClientType(Type type, string appUrl);
static member RegisterActivatedClientType : Type * string -> unit
Public Shared Sub RegisterActivatedClientType (type As Type, appUrl As String)
參數
- appUrl
- String
啟用此類型應用程式的網址。
例外狀況
type或appUrl參數為 null。
呼叫堆疊中至少有一個呼叫者沒有權限設定遠端存取類型和通道。
範例
以下程式碼範例展示了客戶端將某物件類型註冊為可在伺服器上啟用的類型。 對於對應於呈現客戶端程式碼的伺服器程式碼,請參考範例說明此 RegisterActivatedServiceType 方法。
#using <system.dll>
#using <system.runtime.remoting.dll>
#using "service.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( gcnew TcpChannel );
RemotingConfiguration::RegisterActivatedClientType( HelloServiceClass::typeid, "tcp://localhost:8082" );
try
{
HelloServiceClass ^ service = gcnew HelloServiceClass;
// 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" );
}
catch (Exception ex)
{
Console::WriteLine("An exception occurred: " + ex.Message);
}
Console::WriteLine();
return 0;
}
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");
try
{
HelloServiceClass service = new HelloServiceClass();
// 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();
}
catch (Exception ex)
{
Console.WriteLine("An exception occurred: " + ex.Message);
}
}
}
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")
Try
Dim service As New HelloServiceClass()
' 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")
Catch ex as Exception
Console.WriteLine("An exception occurred: " + ex.Message)
End Try
Console.WriteLine()
End Sub
End Class
備註
要在伺服器端建立由客戶端啟動的物件實例,你必須知道它 Type ,並且必須透過此 RegisterActivatedServiceType 方法在伺服器端註冊。 要取得用戶端啟用物件新實例的代理,用戶端必須先註冊一個通道, ChannelServices 然後透過呼叫 new來啟動該物件。
要啟用由客戶端啟用的物件類型,並使用 new 關鍵字,您必須先在用戶端使用該 RegisterActivatedClientType 方法註冊該物件類型。 呼叫該 RegisterActivatedClientType 方法會讓遠端基礎設施知道遠端應用程式的位置,並 new 嘗試建立該應用程式。 反之,若你使用此 Activator.CreateInstance 方法建立客戶端啟用物件的新實例,必須提供遠端應用程式的 URL 作為參數,因此客戶端無需事先註冊。 若要提供 Activator.CreateInstance 該方法並提供你想建立物件的伺服器 URL,你必須將該 URL 封裝在該類別的 UrlAttribute 實例中。