System.Runtime.Remoting.RemotingConfiguration Class

Assembly: Mscorlib.dll
Namespace: System.Runtime.Remoting
Summary
Provides various static methods for configuring the remoting infrastructure.
C# Syntax:
public class RemotingConfiguration
See also:
System.Runtime.Remoting Namespace

System.Runtime.Remoting.RemotingConfiguration Member List:

Public Properties
ApplicationId Read-only

Gets the ID of the currently executing application.
ApplicationName Read-write

Gets or sets the name of a remoting application.
ProcessId Read-only

Gets the ID of the currently executing process.
Public Methods
Configure Reads the configuration file and configures the remoting infrastructure.
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetRegisteredActivatedClientTypes Retrieves an array of object types registered on the client as types that will be activated remotely.
GetRegisteredActivatedServiceTypes Retrieves an array of object types registered on the service end that can be activated on request from a client.
GetRegisteredWellKnownClientTypes Retrieves an array of object types registered on the client end as well-known types.
GetRegisteredWellKnownServiceTypes Retrieves an array of object types registered on the service end as well-known types.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
IsActivationAllowed Returns a Boolean value indicating whether the specified Type is allowed to be client activated.
IsRemotelyActivatedClientType Overloaded:
IsRemotelyActivatedClientType(Type svrType)

Checks whether the specified object Type is registered as a remotely activated client type.
IsRemotelyActivatedClientType Overloaded:
IsRemotelyActivatedClientType(string typeName, string assemblyName)

Checks whether the object specified by its type name and assembly name is registered as a remotely activated client type.
IsWellKnownClientType Overloaded:
IsWellKnownClientType(Type svrType)

Checks whether the specified object Type is registered as a well-known client type.
IsWellKnownClientType Overloaded:
IsWellKnownClientType(string typeName, string assemblyName)

Checks whether the object specified by its type name and assembly name is registered as a well-known client type.
RegisterActivatedClientType Overloaded:
RegisterActivatedClientType(ActivatedClientTypeEntry entry)

Registers an object Type recorded in the provided ActivatedClientTypeEntry on the client end as a type that can be activated on the server.
RegisterActivatedClientType Overloaded:
RegisterActivatedClientType(Type type, string appUrl)

Registers an object Type on the client end as a type that can be activated on the server, using the given parameters to initialize a new instance of the ActivatedClientTypeEntry class.
RegisterActivatedServiceType Overloaded:
RegisterActivatedServiceType(ActivatedServiceTypeEntry entry)

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 Overloaded:
RegisterActivatedServiceType(Type type)

Registers a specified object type on the service end as a type that can be activated on request from a client.
RegisterWellKnownClientType Overloaded:
RegisterWellKnownClientType(WellKnownClientTypeEntry entry)

Registers an object Type recorded in the provided WellKnownClientTypeEntry on the client end as a well-known type that can be activated on the server.
RegisterWellKnownClientType Overloaded:
RegisterWellKnownClientType(Type type, string objectUrl)

Registers an object Type on the client end as a well-known type that can be activated on the server, using the given parameters to initialize a new instance of the WellKnownClientTypeEntry class.
RegisterWellKnownServiceType Overloaded:
RegisterWellKnownServiceType(WellKnownServiceTypeEntry entry)

Registers an object Type recorded in the provided WellKnownServiceTypeEntry on the service end as a well-known type.
RegisterWellKnownServiceType Overloaded:
RegisterWellKnownServiceType(Type type, string objectUri, WellKnownObjectMode mode)

Registers an object Type on the service end as a well-known type, using the given parameters to initialize a new instance of WellKnownServiceTypeEntry.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Runtime.Remoting.RemotingConfiguration Member Details

Property: ApplicationId (read-only)
Summary
Gets the ID of the currently executing application.
C# Syntax:
public static string ApplicationId {get;}
Remarks
The application ID is prepended to the URI of the objects created by the currently executing application.
.NET Framework Security:
SecurityPermission for configuration of the remoting infrastructure. Associated enumeration: SecurityPermissionFlag.RemotingConfiguration.

Return to top


Property: ApplicationName (read-write)
Summary
Gets or sets the name of a remoting application.
C# Syntax:
public static string ApplicationName {get; set;}
Remarks
An application name can be set only once, either through the current property or through a configuration file. If an application is running inside a hosted environment, such as Internet Information Services (IIS), this value might have already been set (usually to the virtual directory). The current property will return null if the application name has not been set.
Example
The following example demonstrates the use of the RemotingConfiguration.ApplicationName property to indicate the name of the remoting application. For the full example code, see examples for the RemotingConfiguration.RegisterWellKnownClientType and RemotingConfiguration.RegisterWellKnownServiceType methods.
        ChannelServices.RegisterChannel(new TcpChannel(8082));

        RemotingConfiguration.ApplicationName = "HelloServiceApplication";

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

    

The following example demonstrates how to access an object remoted from a named application.

        ChannelServices.RegisterChannel(new TcpChannel());

        RemotingConfiguration.RegisterWellKnownClientType(
                                                           typeof(HelloService),
                                                           "tcp://localhost:8082/HelloServiceApplication/MyUri"
                                                         );

        HelloService service = new HelloService();

    

Return to top


Property: ProcessId (read-only)
Summary
Gets the ID of the currently executing process.
C# Syntax:
public static string ProcessId {get;}

Return to top


Method: Configure(
   string filename
)
Summary
Reads the configuration file and configures the remoting infrastructure.
C# Syntax:
public static void Configure(
   string filename
);
Parameters:

filename

The name of the remoting configuration file. Can be null.

Remarks
Passing null as the filename parameter will cause default remoting initialization without requiring the existence of a configuration file.

For configuration file syntax, see .

.NET Framework Security:
SecurityPermission for configuration of the remoting infrastructure. Associated enumeration: SecurityPermissionFlag.RemotingConfiguration.

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~RemotingConfiguration();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetRegisteredActivatedClientTypes()
Summary
Retrieves an array of object types registered on the client as types that will be activated remotely.
C# Syntax:
public static ActivatedClientTypeEntry[] GetRegisteredActivatedClientTypes();
Return Value:
An array of object types registered on the client as types that will be activated remotely.
Remarks
For a detailed description of client activated objects see the conceptual topic at MSDN: clientactivation.
.NET Framework Security:
SecurityPermission for configuration of the remoting infrastructure. Associated enumeration: SecurityPermissionFlag.RemotingConfiguration.
See also:
ActivatedServiceTypeEntry | ActivatedClientTypeEntry | RemotingConfiguration.RegisterActivatedServiceType | RemotingConfiguration.RegisterActivatedClientType

Return to top


Method: GetRegisteredActivatedServiceTypes()
Summary
Retrieves an array of object types registered on the service end that can be activated on request from a client.
C# Syntax:
public static ActivatedServiceTypeEntry[] GetRegisteredActivatedServiceTypes();
Return Value:
An array of object types registered on the service end that can be activated on request from a client.
Remarks
For a detailed description of client activated objects see the conceptual topic at MSDN: clientactivation.
.NET Framework Security:
SecurityPermission for configuration of the remoting infrastructure. Associated enumeration: SecurityPermissionFlag.RemotingConfiguration.
See also:
ActivatedServiceTypeEntry | ActivatedClientTypeEntry | RemotingConfiguration.RegisterActivatedServiceType | RemotingConfiguration.RegisterActivatedClientType

Return to top


Method: GetRegisteredWellKnownClientTypes()
Summary
Retrieves an array of object types registered on the client end as well-known types.
C# Syntax:
public static WellKnownClientTypeEntry[] GetRegisteredWellKnownClientTypes();
Return Value:
An array of object types registered on the client end as well-known types.
Remarks
Well-known object types can be either single call or singleton. If an object type is single call, then a new instance of it is created each time a call from the client comes in. All calls to a singleton object are handled by one instance of that object.

For a more detailed description of well-known objects see the conceptual topic at MSDN: serveractivation.

.NET Framework Security:
SecurityPermission for configuration of the remoting infrastructure. Associated enumeration: SecurityPermissionFlag.RemotingConfiguration.
See also:
WellKnownClientTypeEntry | WellKnownServiceTypeEntry | RemotingConfiguration.RegisterWellKnownServiceType | RemotingConfiguration.RegisterWellKnownClientType

Return to top


Method: GetRegisteredWellKnownServiceTypes()
Summary
Retrieves an array of object types registered on the service end as well-known types.
C# Syntax:
public static WellKnownServiceTypeEntry[] GetRegisteredWellKnownServiceTypes();
Return Value:
An array of object types registered on the service end as well-known types.
Remarks
Well-known object types can be either single call or singleton. If an object type is single call, then a new instance of it is created each time a call from the client comes in. All calls to a singleton object are handled by one instance of that object.

For a more detailed description of well-known objects see the conceptual topic at MSDN: serveractivation.

.NET Framework Security:
SecurityPermission for configuration of the remoting infrastructure. Associated enumeration: SecurityPermissionFlag.RemotingConfiguration.
See also:
WellKnownServiceTypeEntry | WellKnownClientTypeEntry | RemotingConfiguration.RegisterWellKnownServiceType | RemotingConfiguration.RegisterWellKnownClientType

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: IsActivationAllowed(
   Type svrType
)
Summary
Returns a Boolean value indicating whether the specified Type is allowed to be client activated.
C# Syntax:
public static bool IsActivationAllowed(
   Type svrType
);
Parameters:

svrType

The object Type to check.

Return Value:
true if the specified Type is allowed to be client activated; otherwise, false.
Remarks
The current method is used at the server end to determine whether an activation of the object Type is explicitly allowed by the server.
.NET Framework Security:
SecurityPermission for configuration of the remoting infrastructure. Associated enumeration: SecurityPermissionFlag.RemotingConfiguration.

Return to top


Overloaded Method: IsRemotelyActivatedClientType(
   Type svrType
)
Summary
Checks whether the specified object Type is registered as a remotely activated client type.
C# Syntax:
public static ActivatedClientTypeEntry IsRemotelyActivatedClientType(
   Type svrType
);
Parameters:

svrType

The object type to check.

Return Value:
The ActivatedClientTypeEntry corresponding to the specified object type.
.NET Framework Security:
SecurityPermission for configuration of the remoting infrastructure. Associated enumeration: SecurityPermissionFlag.RemotingConfiguration.
See also:
MSDN: clientactivation

Return to top


Overloaded Method: IsRemotelyActivatedClientType(
   string typeName,
   string assemblyName
)
Summary
Checks whether the object specified by its type name and assembly name is registered as a remotely activated client type.
C# Syntax:
public static ActivatedClientTypeEntry IsRemotelyActivatedClientType(
   string typeName,
   string assemblyName
);
Parameters:

typeName

The type name of the object to check.

assemblyName

The assembly name of the object to check.

Return Value:
The ActivatedClientTypeEntry corresponding to the specified object type.
.NET Framework Security:
SecurityPermission for configuration of the remoting infrastructure. Associated enumeration: SecurityPermissionFlag.RemotingConfiguration.
See also:
MSDN: clientactivation

Return to top


Overloaded Method: IsWellKnownClientType(
   Type svrType
)
Summary
Checks whether the specified object Type is registered as a well-known client type.
C# Syntax:
public static WellKnownClientTypeEntry IsWellKnownClientType(
   Type svrType
);
Parameters:

svrType

The object Type to check.

Return Value:
The WellKnownClientTypeEntry corresponding to the specified object type.
.NET Framework Security:
SecurityPermission for configuration of the remoting infrastructure. Associated enumeration: SecurityPermissionFlag.RemotingConfiguration.
See also:
MSDN: serveractivation

Return to top


Overloaded Method: IsWellKnownClientType(
   string typeName,
   string assemblyName
)
Summary
Checks whether the object specified by its type name and assembly name is registered as a well-known client type.
C# Syntax:
public static WellKnownClientTypeEntry IsWellKnownClientType(
   string typeName,
   string assemblyName
);
Parameters:

typeName

The type name of the object to check.

assemblyName

The assembly name of the object to check.

Return Value:
The WellKnownClientTypeEntry corresponding to the specified object type.
.NET Framework Security:
SecurityPermission for configuration of the remoting infrastructure. Associated enumeration: SecurityPermissionFlag.RemotingConfiguration.
See also:
MSDN: serveractivation

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: RegisterActivatedClientType(
   ActivatedClientTypeEntry entry
)
Summary
Registers an object Type recorded in the provided ActivatedClientTypeEntry on the client end as a type that can be activated on the server.
C# Syntax:
public static void RegisterActivatedClientType(
   ActivatedClientTypeEntry entry
);
Parameters:

entry

Configuration settings for the client activated type.

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 RemotingConfiguration.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.

To activate a client activated object type with the new keyword, you must first register the object type on the client end using the RemotingConfiguration.RegisterActivatedClientType method. Calling the RemotingConfiguration.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 Activator.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 Activator.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 the conceptual topic at MSDN: clientactivation.

.NET Framework Security:
SecurityPermission for configuration of the remoting infrastructure. Associated enumeration: SecurityPermissionFlag.RemotingConfiguration.
See also:
ActivatedClientTypeEntry | ActivatedServiceTypeEntry

Return to top


Overloaded Method: RegisterActivatedClientType(
   Type type,
   string appUrl
)
Summary
Registers an object Type on the client end as a type that can be activated on the server, using the given parameters to initialize a new instance of the ActivatedClientTypeEntry class.
C# Syntax:
public static void RegisterActivatedClientType(
   Type type,
   string appUrl
);
Parameters:

type

The object Type.

appUrl

URL of the application where this type is activated.

Exceptions
Exception Type Condition
ArgumentNullException The typeName or URI parameter is null.
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 RemotingConfiguration.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.

To activate a client activated object type with the new keyword, you must first register the object type on the client end using the RemotingConfiguration.RegisterActivatedClientType method. Calling the RemotingConfiguration.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 Activator.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 Activator.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 the conceptual topic at MSDN: clientactivation

Example
The following example demonstrates registration of an object type on the client end as a type that can be activated on the server. For the server code that corresponds to the presented client code, see the example for the RemotingConfiguration.RegisterActivatedServiceType method.
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

public class ClientClass {

    public static void Main() { 

        ChannelServices.RegisterChannel(new TcpChannel());

        RemotingConfiguration.RegisterActivatedClientType(typeof(HelloServiceClass),
                                                   "tcp://localhost:8082");

        HelloServiceClass service = new HelloServiceClass();

        if(service == null) {
            Console.WriteLine("Could not locate server.");
            return;
        }

        // Calls the remote method.
        Console.WriteLine();
        Console.WriteLine("Calling remote object");
        Console.WriteLine(service.HelloMethod("Caveman"));
        Console.WriteLine(service.HelloMethod("Spaceman"));
        Console.WriteLine(service.HelloMethod("Client Man"));
        Console.WriteLine("Finished remote object call");
        Console.WriteLine();
    }
}

    
.NET Framework Security:
SecurityPermission for configuration of the remoting infrastructure. Associated enumeration: SecurityPermissionFlag.RemotingConfiguration.
See also:
ActivatedClientTypeEntry | ActivatedServiceTypeEntry

Return to top


Overloaded Method: RegisterActivatedServiceType(
   ActivatedServiceTypeEntry entry
)
Summary
Registers an object type recorded in the provided ActivatedServiceTypeEntry on the service end as one that can be activated on request from a client.
C# Syntax:
public static void RegisterActivatedServiceType(
   ActivatedServiceTypeEntry entry
);
Parameters:

entry

Configuration settings for the client activated type.

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 RemotingConfiguration.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 RemotingConfiguration.RegisterActivatedClientType method. Calling the RemotingConfiguration.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 Activator.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 Activator.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 the conceptual topic at MSDN: clientactivation.

.NET Framework Security:
SecurityPermission for configuration of the remoting infrastructure. Associated enumeration: SecurityPermissionFlag.RemotingConfiguration.
See also:
ActivatedServiceTypeEntry | ActivatedClientTypeEntry

Return to top


Overloaded Method: RegisterActivatedServiceType(
   Type type
)
Summary
Registers a specified object type on the service end as a type that can be activated on request from a client.
C# Syntax:
public static void RegisterActivatedServiceType(
   Type type
);
Parameters:

type

The Type of object to register.

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 RemotingConfiguration.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 RemotingConfiguration.RegisterActivatedClientType method. Calling the RemotingConfiguration.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 Activator.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 Activator.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 the conceptual topic at MSDN: clientactivation.

Example
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 RemotingConfiguration.RegisterActivatedClientType method.
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();
    }
}

    

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

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 + ".";
    }
}

    
.NET Framework Security:
SecurityPermission for configuration of the remoting infrastructure. Associated enumeration: SecurityPermissionFlag.RemotingConfiguration.
See also:
ActivatedServiceTypeEntry | ActivatedClientTypeEntry

Return to top


Overloaded Method: RegisterWellKnownClientType(
   WellKnownClientTypeEntry entry
)
Summary
Registers an object Type recorded in the provided WellKnownClientTypeEntry on the client end as a well-known type that can be activated on the server.
C# Syntax:
public static void RegisterWellKnownClientType(
   WellKnownClientTypeEntry entry
);
Parameters:

entry

Configuration settings for the well-known type.

Remarks
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 Activator.GetObject. To activate a well-known object with new, you must first register the well-known object type on the client using the RemotingConfiguration.RegisterWellKnownClientType method. Calling the RemotingConfiguration.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.

For a detailed description of well-known objects see the conceptual topic at MSDN: serveractivation.

.NET Framework Security:
SecurityPermission for configuration of the remoting infrastructure. Associated enumeration: SecurityPermissionFlag.RemotingConfiguration.
See also:
WellKnownClientTypeEntry | WellKnownServiceTypeEntry

Return to top


Overloaded Method: RegisterWellKnownClientType(
   Type type,
   string objectUrl
)
Summary
Registers an object Type on the client end as a well-known type that can be activated on the server, using the given parameters to initialize a new instance of the WellKnownClientTypeEntry class.
C# Syntax:
public static void RegisterWellKnownClientType(
   Type type,
   string objectUrl
);
Parameters:

type

The object Type.

objectUrl

URL of a well-known client object.

Remarks
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 Activator.GetObject. To activate a well-known object with new, you must first register the well-known object type on the client using the RemotingConfiguration.RegisterWellKnownClientType method. Calling the RemotingConfiguration.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.

For a detailed description of well-known objects see the conceptual topic at MSDN: serveractivation.

Example
The following example demonstrates registration of an object type on the client end as a well-known type. For the server code that corresponds to the presented client code, see the example for the RemotingConfiguration.RegisterWellKnownServiceType method.
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels;


public class ClientClass {

    public static void Main() { 

	. . . 
        ChannelServices.RegisterChannel(new TcpChannel());

        RemotingConfiguration.RegisterWellKnownClientType(
                                                           typeof(HelloService),
                                                           "tcp://localhost:8082/HelloServiceApplication/MyUri"
                                                         );

        HelloService service = new HelloService();
	. . . 

        if(service == null) {
            Console.WriteLine("Could not locate server.");
            return;
        }


        // Calls the remote method.
        Console.WriteLine();
        Console.WriteLine("Calling remote object");
        Console.WriteLine(service.HelloMethod("Caveman"));
        Console.WriteLine(service.HelloMethod("Spaceman"));
        Console.WriteLine(service.HelloMethod("Client Man"));
        Console.WriteLine("Finished remote object call");
        Console.WriteLine();
    }
}

    
.NET Framework Security:
SecurityPermission for configuration of the remoting infrastructure. Associated enumeration: SecurityPermissionFlag.RemotingConfiguration.
See also:
WellKnownClientTypeEntry | WellKnownServiceTypeEntry

Return to top


Overloaded Method: RegisterWellKnownServiceType(
   WellKnownServiceTypeEntry entry
)
Summary
Registers an object Type recorded in the provided WellKnownServiceTypeEntry on the service end as a well-known type.
C# Syntax:
public static void RegisterWellKnownServiceType(
   WellKnownServiceTypeEntry entry
);
Parameters:

entry

Configuration settings for the well-known type.

Remarks
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 RemotingConfiguration.RegisterWellKnownClientType method. Calling the RemotingConfiguration.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, .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 WellKnownObjectMode.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 the conceptual topic at MSDN: serveractivation.

Example
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Serialization;


public class ObjRefExample {

   public static void Main() {

      ChannelServices.RegisterChannel(new HttpChannel(8090));

      WellKnownServiceTypeEntry wkste = 
         new WellKnownServiceTypeEntry(typeof(RemoteObject), 
                                       "RemoteObject", 
                                       WellKnownObjectMode.Singleton);
      
      RemotingConfiguration.RegisterWellKnownServiceType( wkste );

      RemoteObject RObj = 
         (RemoteObject)Activator.GetObject(typeof(RemoteObject), 
                                           "http://localhost:8090/RemoteObject");

      LocalObject LObj = new LocalObject();
      
      RObj.Method1( LObj );

      Console.WriteLine("Press Return to exit...");
      Console.ReadLine();
   }
}

 
public class RemoteObject : MarshalByRefObject {

   public void Method1(LocalObject param) {
      Console.WriteLine("Invoked: Method1({0})", param);
   }
}

    
.NET Framework Security:
SecurityPermission for configuration of the remoting infrastructure. Associated enumeration: SecurityPermissionFlag.RemotingConfiguration.
See also:
WellKnownServiceTypeEntry | WellKnownClientTypeEntry

Return to top


Overloaded Method: RegisterWellKnownServiceType(
   Type type,
   string objectUri,
   WellKnownObjectMode mode
)
Summary
Registers an object Type on the service end as a well-known type, using the given parameters to initialize a new instance of WellKnownServiceTypeEntry.
C# Syntax:
public static void RegisterWellKnownServiceType(
   Type type,
   string objectUri,
   WellKnownObjectMode mode
);
Parameters:

type

The object Type.

objectUri

The object URI.

mode

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

Remarks
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 RemotingConfiguration.RegisterWellKnownClientType method. Calling the RemotingConfiguration.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 WellKnownObjectMode.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 the conceptual topic at MSDN: serveractivation.

Example
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 RemotingConfiguration.RegisterWellKnownClientType method.
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();
    }
}

    

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

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 + ".";
    }
}

    
.NET Framework Security:
SecurityPermission for configuration of the remoting infrastructure. Associated enumeration: SecurityPermissionFlag.RemotingConfiguration.
See also:
WellKnownServiceTypeEntry | WellKnownClientTypeEntry

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.