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.

public:
 static System::Object ^ Connect(Type ^ classToProxy, System::String ^ url);
public static object Connect (Type classToProxy, string url);
[System.Runtime.InteropServices.ComVisible(true)]
public static object Connect (Type classToProxy, string url);
[System.Runtime.InteropServices.ComVisible(true)]
[System.Security.SecurityCritical]
public static object Connect (Type classToProxy, string url);
static member Connect : Type * string -> obj
[<System.Runtime.InteropServices.ComVisible(true)>]
static member Connect : Type * string -> obj
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Security.SecurityCritical>]
static member Connect : Type * string -> obj
Public Shared Function Connect (classToProxy As Type, url As String) As Object

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.

Console::WriteLine( "Connecting to SampleNamespace::SampleWellKnown." );
SampleWellKnown ^ proxy = dynamic_cast<SampleWellKnown^>(RemotingServices::Connect( SampleWellKnown::typeid, const_cast<String^>(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 ) );
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));
Console.WriteLine("Connecting to SampleNamespace.SampleWellKnown.")

Dim proxy As SampleWellKnown = _
   CType(RemotingServices.Connect(GetType(SampleWellKnown), SERVER_URL), SampleWellKnown)

Console.WriteLine("Connected to SampleWellKnown")

' Verifies that the object reference is to a transparent proxy.
If RemotingServices.IsTransparentProxy(proxy) Then
   Console.WriteLine("proxy is a reference to a transparent proxy.")
Else
   Console.WriteLine("proxy is not a transparent proxy.  This is unexpected.")
End If

' 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

Connect(Type, String, Object)

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

public:
 static System::Object ^ Connect(Type ^ classToProxy, System::String ^ url, System::Object ^ data);
public static object Connect (Type classToProxy, string url, object data);
[System.Runtime.InteropServices.ComVisible(true)]
public static object Connect (Type classToProxy, string url, object data);
[System.Runtime.InteropServices.ComVisible(true)]
[System.Security.SecurityCritical]
public static object Connect (Type classToProxy, string url, object data);
static member Connect : Type * string * obj -> obj
[<System.Runtime.InteropServices.ComVisible(true)>]
static member Connect : Type * string * obj -> obj
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Security.SecurityCritical>]
static member Connect : Type * string * obj -> obj
Public Shared Function Connect (classToProxy As Type, url As String, data As Object) As Object

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