RemotingConfiguration.RegisterWellKnownClientType Method (Type, String)

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.

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

[SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.RemotingConfiguration)]
public static void RegisterWellKnownClientType(
	Type type,
	string objectUrl
)

Parameters

type
Type: System.Type

The object Type.

objectUrl
Type: System.String

URL of a well-known client object.

ExceptionCondition
SecurityException

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 Activator.GetObject. 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.

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

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

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft