Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

RemotingConfiguration.RegisterWellKnownServiceType Method (Type, String, WellKnownObjectMode)

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

Namespace:  System.Runtime.Remoting
Assembly:  mscorlib (in mscorlib.dll)

<SecurityPermissionAttribute(SecurityAction.Demand, Flags := SecurityPermissionFlag.RemotingConfiguration)> _
Public Shared Sub RegisterWellKnownServiceType ( _
	type As Type, _
	objectUri As String, _
	mode As WellKnownObjectMode _


Type: System.Type

The object Type.

Type: System.String

The object URI.

Type: System.Runtime.Remoting.WellKnownObjectMode

The activation mode of the well-known object type being registered. (See WellKnownObjectMode.)


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

Any client that knows the URI of a registered well-known object can obtain a proxy for the object by registering the channel it prefers with ChannelServices, and activating the object by calling new or the Activator.GetObject method. To activate a well-known object with new, you must first register the well-known object type on the client using the RegisterWellKnownClientType method. Calling the RegisterWellKnownClientType method gives the remoting infrastructure the location of the remote object, which allows the new keyword to create it. If, on the other hand, you use the Activator.GetObject method to activate the well-known object, you must supply it with the object's URL as an argument, so no prior registration on the client end is necessary.

When the call arrives at the server, the .NET Framework extracts the URI from the message, examines the remoting tables to locate the reference for the object that matches the URI, and then instantiates the object if necessary, forwarding the method call to the object. If the object is registered as SingleCall, it is destroyed after the method call is completed. A new instance of the object is created for each method called. The only difference between Activator.GetObject and new is that the former allows you to specify a URL as a parameter, and the latter obtains the URL from the configuration.

The remote object itself is not instantiated by the registration process. This only happens when a client attempts to call a method on the object or activates the object from the client side.

For a detailed description of well-known objects, see [<topic://cpconServerActivation>].

The following code 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.

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.")

   End Sub 'Main

End Class 'ServerClass

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

Imports System

Public Class HelloService
   Inherits MarshalByRefObject

   Private Shared n_instances As Integer 

   Public Sub New()
      n_instances += 1
      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
   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

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

© 2015 Microsoft