RemotingServices.Connect Method

Definition

Creates a proxy for a well-known object.

Overloads

Connect(Type, String)

Creates a proxy for a well-known object, given the Type and URL.

Connect(Type, String, Object)

Creates a proxy for a well-known object, given the Type, URL, and channel-specific data.

Connect(Type, String)

Creates a proxy for a well-known object, given the Type and URL.

C#
public static object Connect(Type classToProxy, string url);
C#
[System.Runtime.InteropServices.ComVisible(true)]
public static object Connect(Type classToProxy, string url);
C#
[System.Runtime.InteropServices.ComVisible(true)]
[System.Security.SecurityCritical]
public static object Connect(Type classToProxy, string url);

Parameters

classToProxy
Type

The Type of a well-known object on the server end to which you want to connect.

url
String

The URL of the server class.

Returns

A proxy to the remote object that points to an endpoint served by the specified well-known object.

Attributes

Exceptions

The immediate caller does not have permission to configure remoting types and channels.

Examples

The following code example demonstrates how to use the Connect method to create a proxy to a well-known object.

C#
Console.WriteLine("Connecting to SampleNamespace.SampleWellKnown.");

SampleWellKnown proxy =
   (SampleWellKnown)RemotingServices.Connect(typeof(SampleWellKnown), SERVER_URL);

Console.WriteLine("Connected to SampleWellKnown");

// Verifies that the object reference is to a transparent proxy.
if (RemotingServices.IsTransparentProxy(proxy))
    Console.WriteLine("proxy is a reference to a transparent proxy.");
else
    Console.WriteLine("proxy is not a transparent proxy.  This is unexpected.");

// Calls a method on the server object.
Console.WriteLine("proxy.Add returned {0}.", proxy.Add(2, 3));

Remarks

The returned proxy object points to an endpoint served by the specified well-known object. No messages are sent over the network until a method is called on the proxy.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Connect(Type, String, Object)

Creates a proxy for a well-known object, given the Type, URL, and channel-specific data.

C#
public static object Connect(Type classToProxy, string url, object data);
C#
[System.Runtime.InteropServices.ComVisible(true)]
public static object Connect(Type classToProxy, string url, object data);
C#
[System.Runtime.InteropServices.ComVisible(true)]
[System.Security.SecurityCritical]
public static object Connect(Type classToProxy, string url, object data);

Parameters

classToProxy
Type

The Type of the well-known object to which you want to connect.

url
String

The URL of the well-known object.

data
Object

Channel specific data. Can be null.

Returns

A proxy that points to an endpoint that is served by the requested well-known object.

Attributes

Exceptions

The immediate caller does not have permission to configure remoting types and channels.

Remarks

The returned proxy object points to an endpoint served by the specified well-known object. No messages are sent over the network until a method is called on the proxy.

The data object is used to communicate information to the channel, and is passed to the IChannelSender.CreateMessageSink method.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1