Edit

Share via


RemotingConfiguration.RegisterActivatedServiceType Method

Definition

Registers an object Type on the service end as one that can be activated on request from a client.

Overloads

RegisterActivatedServiceType(ActivatedServiceTypeEntry)

Registers an object type recorded in the provided ActivatedServiceTypeEntry on the service end as one that can be activated on request from a client.

RegisterActivatedServiceType(Type)

Registers a specified object type on the service end as a type that can be activated on request from a client.

RegisterActivatedServiceType(ActivatedServiceTypeEntry)

Registers an object type recorded in the provided ActivatedServiceTypeEntry on the service end as one that can be activated on request from a client.

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)

Parameters

entry
ActivatedServiceTypeEntry

Configuration settings for the client-activated type.

Exceptions

At least one of the callers higher in the callstack does not have permission to configure remoting types and channels.

Remarks

To create an instance of a client-activated object on the server, you must know its Type and it must be registered on the server end by using the RegisterActivatedServiceType method. To obtain a proxy for a new instance of the client-activated object, the client must first register a channel with ChannelServices and then activate the object by calling new or Activator.CreateInstance.

To activate a client-activated object type with the new keyword, you must first register the object type on the client end using the RegisterActivatedClientType method. Calling the RegisterActivatedClientType method gives the remoting infrastructure the location of the remote application, where new attempts to create it. If, on the other hand, you use the CreateInstance method to create a new instance of the client-activated object, you must supply the remote application's URL as a parameter, so no prior registration on the client end is necessary. To supply the CreateInstance method with the URL of the server where you want to create the object, you must encapsulate the URL in an instance of the UrlAttribute class.

For a detailed description of client-activated objects, see Client Activation.

See also

Applies to

RegisterActivatedServiceType(Type)

Registers a specified object type on the service end as a type that can be activated on request from a client.

public:
 static void RegisterActivatedServiceType(Type ^ type);
public static void RegisterActivatedServiceType (Type type);
static member RegisterActivatedServiceType : Type -> unit
Public Shared Sub RegisterActivatedServiceType (type As Type)

Parameters

type
Type

The Type of object to register.

Exceptions

At least one of the callers higher in the callstack does not have permission to configure remoting types and channels.

Examples

The following code example demonstrates registration of an object type on the server as a type that can be activated by the client. For the client code that corresponds to the presented server code, see the example for the RegisterActivatedClientType method.

#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

The following code example shows the service object registered in the sample code above.

#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

Remarks

To create an instance of a client-activated object on the server, you must know its Type and it must be registered on the server end by using the RegisterActivatedServiceType method. To obtain a proxy for a new instance of the client-activated object, the client must first register a channel with ChannelServices and then activate the object by calling new or Activator.CreateInstance.

To activate a client-activated object type with the new keyword, you must first register the object type on the client end using the RegisterActivatedClientType method. Calling the RegisterActivatedClientType method gives the remoting infrastructure the location of the remote application, where new attempts to create it. If, on the other hand, you use the CreateInstance method to create a new instance of the client-activated object, you must supply the remote application's URL as a parameter, so no prior registration on the client end is necessary. To supply the CreateInstance method with the URL of the server where you want to create the object, you must encapsulate the URL in an instance of the UrlAttribute class.

For a detailed description of client-activated objects, see Client Activation.

See also

Applies to