Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 1.1
.NET Framework
Reference
Methods
This page is specific to
Microsoft Visual Studio 2003/.NET Framework 1.1

Other versions are also available for the following:
.NET Framework Class Library
RemotingConfiguration.RegisterWellKnownServiceType Method

Registers an object Type on the service end as a well-known type (single call or singleton).

Overload List

Registers an object Type recorded in the provided WellKnownServiceTypeEntry on the service end as a well-known type.

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

Registers an object Type on the service end as a well-known type, using the given parameters to initialize a new instance of WellKnownServiceTypeEntry.

[Visual Basic] Overloads Public Shared Sub RegisterWellKnownServiceType(Type, String, WellKnownObjectMode)
[C#] public static void RegisterWellKnownServiceType(Type, string, WellKnownObjectMode);
[C++] public: static void RegisterWellKnownServiceType(Type*, String*, WellKnownObjectMode);
[JScript] public static function RegisterWellKnownServiceType(Type, String, WellKnownObjectMode);

Example

[Visual Basic, C#, C++] The following example demonstrates registration of an object type on the server as a well-known object type. For the client code that corresponds to the presented server code, see the example for the RegisterWellKnownClientType method.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of RegisterWellKnownServiceType. 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.ApplicationName = "HelloServiceApplication"
      
      RemotingConfiguration.RegisterWellKnownServiceType(GetType(HelloService), "MyUri", WellKnownObjectMode.SingleCall)
    . . . 

      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.ApplicationName = "HelloServiceApplication";

        RemotingConfiguration.RegisterWellKnownServiceType( typeof(HelloService),
                                                            "MyUri",
                                                            WellKnownObjectMode.SingleCall 
                                                          );
    . . . 

        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::ApplicationName = S"HelloServiceApplication";

    RemotingConfiguration::RegisterWellKnownServiceType(__typeof(HelloService),
        S"MyUri",
        WellKnownObjectMode::SingleCall);
    . . . 

    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 HelloService
   Inherits MarshalByRefObject
   
   Private Shared n_instances As Integer
     
   Public Sub New()
      n_instances += 1
      Console.WriteLine("")
      Console.WriteLine("HelloService activated - instance # {0}.", n_instances)
   End Sub 'New
   
   
   Protected Overrides Sub Finalize()
      Console.WriteLine("HelloService instance {0} destroyed.", n_instances)
      n_instances -= 1
      MyBase.Finalize()
   End Sub 'Finalize
   
   
   Public Function HelloMethod(name As [String]) As [String]
      Console.WriteLine("HelloMethod called on HelloService instance {0}.", n_instances)
      Return "Hi there " + name + "."
   End Function 'HelloMethod

End Class 'HelloService

[C#] 
using System;

public class HelloService : MarshalByRefObject {

    static int n_instances;

    public HelloService() {
        n_instances++;
        Console.WriteLine("");
        Console.WriteLine("HelloService activated - instance # {0}.", n_instances);
    }


    ~HelloService()  {
        Console.WriteLine("HelloService instance {0} destroyed.", n_instances);
        n_instances--;
    }


    public String HelloMethod(String name)  {

        Console.WriteLine("HelloMethod called on HelloService instance {0}.", n_instances);
        return "Hi there " + name + ".";
    }
}

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

using namespace System;

public __gc class HelloService : public MarshalByRefObject 
{
    static int n_instances;

public:
    HelloService() 
    {
        n_instances++;
        Console::WriteLine(S"");
        Console::WriteLine(S"HelloService activated - instance # {0}.", __box(n_instances));
    }

    ~HelloService() 
    {
        Console::WriteLine(S"HelloService instance {0} destroyed.", __box(n_instances));
        n_instances--;
    }

public:
    String* HelloMethod(String* name) 
    {
        Console::WriteLine(S"HelloMethod called on HelloService instance {0}.", __box(n_instances));
        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

© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker