RemotingConfiguration.RegisterActivatedServiceType Metoda
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Rejestruje obiekt na końcu usługi jako obiekt Type , który można aktywować na żądanie od klienta.
Przeciążenia
RegisterActivatedServiceType(ActivatedServiceTypeEntry) |
Rejestruje typ obiektu zarejestrowany w podanym ActivatedServiceTypeEntry na końcu usługi jako taki, który można aktywować na żądanie od klienta. |
RegisterActivatedServiceType(Type) |
Rejestruje określony typ obiektu na końcu usługi jako typ, który można aktywować na żądanie od klienta. |
RegisterActivatedServiceType(ActivatedServiceTypeEntry)
Rejestruje typ obiektu zarejestrowany w podanym ActivatedServiceTypeEntry na końcu usługi jako taki, który można aktywować na żądanie od klienta.
public:
static void RegisterActivatedServiceType(System::Runtime::Remoting::ActivatedServiceTypeEntry ^ entry);
public static void RegisterActivatedServiceType (System.Runtime.Remoting.ActivatedServiceTypeEntry entry);
static member RegisterActivatedServiceType : System.Runtime.Remoting.ActivatedServiceTypeEntry -> unit
Public Shared Sub RegisterActivatedServiceType (entry As ActivatedServiceTypeEntry)
Parametry
Ustawienia konfiguracji typu aktywowanego przez klienta.
Wyjątki
Co najmniej jeden z wywołujących wyżej w stosie wywołań nie ma uprawnień do konfigurowania typów i kanałów komunikacji telefonicznej.
Uwagi
Aby utworzyć wystąpienie obiektu aktywowanego przez klienta na serwerze, musisz go znać Type i musi zostać zarejestrowany na końcu serwera przy użyciu RegisterActivatedServiceType metody . Aby uzyskać serwer proxy dla nowego wystąpienia obiektu aktywowanego przez klienta, klient musi najpierw zarejestrować kanał ChannelServices , a następnie aktywować obiekt przez wywołanie metody new
lub Activator.CreateInstance.
Aby aktywować typ obiektu aktywowanego przez klienta za new
pomocą słowa kluczowego , należy najpierw zarejestrować typ obiektu na końcu klienta przy użyciu RegisterActivatedClientType metody .
RegisterActivatedClientType Wywołanie metody daje infrastrukturze komunikacji zdalnej lokalizację aplikacji zdalnej, gdzie new
próbuje ją utworzyć. Jeśli z drugiej strony używasz CreateInstance metody do utworzenia nowego wystąpienia obiektu aktywowanego przez klienta, musisz podać adres URL aplikacji zdalnej jako parametr, więc nie jest wymagana wcześniejsza rejestracja na końcu klienta. Aby podać metodę CreateInstance przy użyciu adresu URL serwera, na którym chcesz utworzyć obiekt, należy hermetyzować adres URL w wystąpieniu UrlAttribute klasy .
Aby uzyskać szczegółowy opis obiektów aktywowanych przez klienta, zobacz Aktywacja klienta.
Zobacz też
Dotyczy
RegisterActivatedServiceType(Type)
Rejestruje określony typ obiektu na końcu usługi jako typ, który można aktywować na żądanie od klienta.
public:
static void RegisterActivatedServiceType(Type ^ type);
public static void RegisterActivatedServiceType (Type type);
static member RegisterActivatedServiceType : Type -> unit
Public Shared Sub RegisterActivatedServiceType (type As Type)
Parametry
Wyjątki
Co najmniej jeden z wywołujących wyżej w stosie wywołań nie ma uprawnień do konfigurowania typów i kanałów komunikacji telefonicznej.
Przykłady
W poniższym przykładzie kodu pokazano rejestrację typu obiektu na serwerze jako typ, który można aktywować przez klienta. Aby uzyskać kod klienta odpowiadający prezentowanemu kodowi serwera, zobacz przykład RegisterActivatedClientType metody .
#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( 8082 ) );
RemotingConfiguration::RegisterActivatedServiceType( HelloServiceClass::typeid );
Console::WriteLine( "Press enter to stop this process." );
Console::ReadLine();
return 0;
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
public class ServerClass {
public static void Main() {
ChannelServices.RegisterChannel(new TcpChannel(8082));
RemotingConfiguration.RegisterActivatedServiceType(typeof(HelloServiceClass));
Console.WriteLine("Press enter to stop this process.");
Console.ReadLine();
}
}
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp
Public Class ServerClass
Public Shared Sub Main()
ChannelServices.RegisterChannel(New TcpChannel(8082))
RemotingConfiguration.RegisterActivatedServiceType(GetType(HelloServiceClass))
Console.WriteLine("Press enter to stop this process.")
Console.ReadLine()
End Sub
End Class
Poniższy przykład kodu przedstawia obiekt usługi zarejestrowany w powyższym przykładowym kodzie.
#using <system.dll>
using namespace System;
public ref class HelloServiceClass: public MarshalByRefObject
{
private:
static int n_instance;
public:
HelloServiceClass()
{
n_instance++;
Console::WriteLine( "{0} has been created. Instance # = {1}", this->GetType()->Name, n_instance );
}
~HelloServiceClass()
{
Console::WriteLine( "Destroyed instance {0} of HelloServiceClass.", n_instance );
n_instance--;
}
String^ HelloMethod( String^ name )
{
// Reports that the method was called.
Console::WriteLine();
Console::WriteLine( "Called HelloMethod on instance {0} with the '{1}' parameter.", n_instance, name );
// Calculates and returns the result to the client.
return String::Format( "Hi there {0}", name );
}
};
using System;
public class HelloServiceClass : MarshalByRefObject {
static int n_instance;
public HelloServiceClass() {
n_instance++;
Console.WriteLine(this.GetType().Name + " has been created. Instance # = {0}", n_instance);
}
~HelloServiceClass() {
Console.WriteLine("Destroyed instance {0} of HelloServiceClass.", n_instance);
n_instance --;
}
public String HelloMethod(String name) {
// Reports that the method was called.
Console.WriteLine();
Console.WriteLine("Called HelloMethod on instance {0} with the '{1}' parameter.",
n_instance, name);
// Calculates and returns the result to the client.
return "Hi there " + name + ".";
}
}
Public Class HelloServiceClass
Inherits MarshalByRefObject
Private Shared n_instance As Integer
Public Sub New()
n_instance += 1
Console.WriteLine(Me.GetType().Name + " has been created. Instance # = {0}", n_instance)
End Sub
Protected Overrides Sub Finalize()
Console.WriteLine("Destroyed instance {0} of HelloServiceClass.", n_instance)
n_instance -= 1
MyBase.Finalize()
End Sub
Public Function HelloMethod(name As [String]) As [String]
' Reports that the method was called.
Console.WriteLine()
Console.WriteLine("Called HelloMethod on instance {0} with the '{1}' parameter.", n_instance, name)
' Calculates and returns the result to the client.
Return "Hi there " + name + "."
End Function 'HelloMethod
End Class
Uwagi
Aby utworzyć wystąpienie obiektu aktywowanego przez klienta na serwerze, musisz go znać Type i musi zostać zarejestrowany na końcu serwera przy użyciu RegisterActivatedServiceType metody . Aby uzyskać serwer proxy dla nowego wystąpienia obiektu aktywowanego przez klienta, klient musi najpierw zarejestrować kanał ChannelServices , a następnie aktywować obiekt przez wywołanie metody new
lub Activator.CreateInstance.
Aby aktywować typ obiektu aktywowanego przez klienta za new
pomocą słowa kluczowego , należy najpierw zarejestrować typ obiektu na końcu klienta przy użyciu RegisterActivatedClientType metody .
RegisterActivatedClientType Wywołanie metody daje infrastrukturze komunikacji zdalnej lokalizację aplikacji zdalnej, gdzie new
próbuje ją utworzyć. Jeśli z drugiej strony używasz CreateInstance metody do utworzenia nowego wystąpienia obiektu aktywowanego przez klienta, musisz podać adres URL aplikacji zdalnej jako parametr, więc nie jest wymagana wcześniejsza rejestracja na końcu klienta. Aby podać metodę CreateInstance przy użyciu adresu URL serwera, na którym chcesz utworzyć obiekt, należy hermetyzować adres URL w wystąpieniu UrlAttribute klasy .
Aby uzyskać szczegółowy opis obiektów aktywowanych przez klienta, zobacz Aktywacja klienta.