Share via


RemotingConfiguration.RegisterWellKnownClientType 方法

定義

在用戶端上登錄物件 Type 為已知型別 (單一呼叫或單一物件)。

多載

RegisterWellKnownClientType(WellKnownClientTypeEntry)

登錄記錄在用戶端上所提供 Type 中的物件 WellKnownClientTypeEntry 為可在伺服器上啟動的已知型別。

RegisterWellKnownClientType(Type, String)

使用指定的參數初始化 Type 類別的新執行個體,在用戶端上將物件 WellKnownClientTypeEntry 登錄為可在伺服器上啟動的已知型別。

RegisterWellKnownClientType(WellKnownClientTypeEntry)

登錄記錄在用戶端上所提供 Type 中的物件 WellKnownClientTypeEntry 為可在伺服器上啟動的已知型別。

public:
 static void RegisterWellKnownClientType(System::Runtime::Remoting::WellKnownClientTypeEntry ^ entry);
public static void RegisterWellKnownClientType (System.Runtime.Remoting.WellKnownClientTypeEntry entry);
static member RegisterWellKnownClientType : System.Runtime.Remoting.WellKnownClientTypeEntry -> unit
Public Shared Sub RegisterWellKnownClientType (entry As WellKnownClientTypeEntry)

參數

entry
WellKnownClientTypeEntry

已知型別的組態設定。

例外狀況

至少有一個呼叫堆疊中較高的呼叫端,不具有設定遠端類型和通道的使用權限。

備註

任何知道已註冊之已知物件 URI 的用戶端都可以藉由註冊偏好 ChannelServices的通道來取得物件的 Proxy,以及藉由呼叫 newActivator.GetObject來啟用物件。 若要使用 new啟動已知的物件,您必須先使用 RegisterWellKnownClientType 方法在用戶端上註冊已知的物件類型。 RegisterWellKnownClientType呼叫 方法會提供遠端基礎結構遠端基礎結構的位置,這可讓 new 關鍵詞建立它。 如果另一方面,您可以使用 Activator.GetObject 方法來啟用已知的物件,則必須以物件的URL作為自變數來提供它,因此不需要在用戶端端進行先前的註冊。

如需已知對象的詳細說明,請參閱 伺服器啟用

另請參閱

適用於

RegisterWellKnownClientType(Type, String)

使用指定的參數初始化 Type 類別的新執行個體,在用戶端上將物件 WellKnownClientTypeEntry 登錄為可在伺服器上啟動的已知型別。

public:
 static void RegisterWellKnownClientType(Type ^ type, System::String ^ objectUrl);
public static void RegisterWellKnownClientType (Type type, string objectUrl);
static member RegisterWellKnownClientType : Type * string -> unit
Public Shared Sub RegisterWellKnownClientType (type As Type, objectUrl As String)

參數

type
Type

物件 Type

objectUrl
String

已知用戶端物件的 URL。

例外狀況

至少有一個呼叫堆疊中較高的呼叫端,不具有設定遠端類型和通道的使用權限。

範例

下列程式代碼範例示範在用戶端上將物件類型註冊為已知型別。 如需對應至所呈現用戶端程式代碼的伺服器程式代碼,請參閱 方法的 RegisterWellKnownServiceType 範例。

#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::Tcp;
using namespace System::Runtime::Remoting::Channels;
int main()
{
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels;

public class ClientClass {

    public static void Main() {
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels.Tcp
Imports System.Runtime.Remoting.Channels


Public Class ClientClass
   
   
   Public Shared Sub Main()
ChannelServices::RegisterChannel( gcnew TcpChannel );
RemotingConfiguration::RegisterWellKnownClientType( HelloService::typeid,
                                                    "tcp://localhost:8082/HelloServiceApplication/MyUri" );
HelloService ^ service = gcnew HelloService;
ChannelServices.RegisterChannel(new TcpChannel());

RemotingConfiguration.RegisterWellKnownClientType(
                                                   typeof(HelloService),
                                                   "tcp://localhost:8082/HelloServiceApplication/MyUri"
                                                 );

HelloService service = new HelloService();
ChannelServices.RegisterChannel(New TcpChannel())

RemotingConfiguration.RegisterWellKnownClientType(GetType(HelloService), "tcp://localhost:8082/HelloServiceApplication/MyUri")

Dim service As New HelloService()
   if ( service == nullptr )
   {
      Console::WriteLine( "Could not locate server." );
      return  -1;
   }

   // 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();
   return 0;
}

        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();
    }
}

      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

End Class

備註

任何知道已註冊之已知物件 URI 的用戶端都可以藉由註冊偏好 ChannelServices的通道來取得物件的 Proxy,以及藉由呼叫 newActivator.GetObject來啟用物件。 若要使用 new啟動已知的物件,您必須先使用 RegisterWellKnownClientType 方法在用戶端上註冊已知的物件類型。 RegisterWellKnownClientType呼叫 方法會提供遠端基礎結構遠端基礎結構的位置,這可讓 new 關鍵詞建立它。 如果另一方面,您可以使用 Activator.GetObject 方法來啟用已知的物件,則必須以物件的URL作為自變數來提供它,因此不需要在用戶端端進行先前的註冊。

如需已知對象的詳細說明,請參閱 伺服器啟用

另請參閱

適用於