Export (0) Print
Expand All

RemotingConfiguration.RegisterActivatedServiceType Method

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

Overload List

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

[Visual Basic] Overloads Public Shared Sub RegisterActivatedServiceType(ActivatedServiceTypeEntry)
[C#] public static void RegisterActivatedServiceType(ActivatedServiceTypeEntry);
[C++] public: static void RegisterActivatedServiceType(ActivatedServiceTypeEntry*);
[JScript] public static function RegisterActivatedServiceType(ActivatedServiceTypeEntry);

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

[Visual Basic] Overloads Public Shared Sub RegisterActivatedServiceType(Type)
[C#] public static void RegisterActivatedServiceType(Type);
[C++] public: static void RegisterActivatedServiceType(Type*);
[JScript] public static function RegisterActivatedServiceType(Type);

Example

[Visual Basic, C#, C++] The following 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.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of RegisterActivatedServiceType. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Imports System
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 'Main

End Class 'ServerClass

[C#] 
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();
    }
}

[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;
using namespace System::Runtime::Remoting::Channels::Tcp;

int main() 
{
    ChannelServices::RegisterChannel(new TcpChannel(8082));

    RemotingConfiguration::RegisterActivatedServiceType(__typeof(HelloServiceClass));

    Console::WriteLine(S"Press enter to stop this process.");
    Console::ReadLine();
    return 0;
}

[Visual Basic, C#, C++] The following example shows the service object registered in the sample code above.

[Visual Basic] 
Imports System

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 'New
      
   
   Protected Overrides Sub Finalize()
      Console.WriteLine("Destroyed instance {0} of HelloServiceClass.", n_instance)
      n_instance -= 1
      MyBase.Finalize()
   End Sub 'Finalize
   
   
   
   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 'HelloServiceClass

[C#] 
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 + ".";
    }
}

[C++] 
#using <mscorlib.dll>
#using <system.dll>

using namespace System;

public __gc class HelloServiceClass : public MarshalByRefObject 
{
    static int n_instance;

public:
    HelloServiceClass() 
    {
        n_instance++;
        Console::WriteLine("{0} has been created.  Instance # = {1}", this->GetType()->Name, __box(n_instance));
    }

    ~HelloServiceClass() 
    {
        Console::WriteLine(S"Destroyed instance {0} of HelloServiceClass.", __box(n_instance));
        n_instance --;
    }

public:
    String* HelloMethod(String* name) 
    {
        // Reports that the method was called.
        Console::WriteLine();
        Console::WriteLine(S"Called HelloMethod on instance {0} with the '{1}' parameter.", 
            __box(n_instance), name);

        // Calculates and returns the result to the client.
        return String::Format(S"Hi there {0}", name);
    }
};

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

RemotingConfiguration Class | RemotingConfiguration Members | System.Runtime.Remoting Namespace

Show:
© 2014 Microsoft