Creates a proxy for a well-known object.
Overload List
Creates a proxy for a well-known object, given the Type and URL.
[Visual Basic] Overloads Public Shared Function Connect(Type, String) As Object
[C#] public static object Connect(Type, string);
[C++] public: static Object* Connect(Type*, String*);
[JScript] public static function Connect(Type, String) : Object;
Creates a proxy for a well-known object, given the Type, URL, and channel-specific data.
[Visual Basic] Overloads Public Shared Function Connect(Type, String, Object) As Object
[C#] public static object Connect(Type, string, object);
[C++] public: static Object* Connect(Type*, String*, Object*);
[JScript] public static function Connect(Type, String, Object) : Object;
Example
[Visual Basic, C#, C++] The following example demonstrates how to use the Connect method to create a proxy to a well-known object.
[Visual Basic, C#, C++] Note This example shows how to use one of the overloaded versions of Connect. For other examples that might be available, see the individual overload topics.
[Visual Basic]
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))
[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));
[C++]
Console::WriteLine(S"Connecting to SampleNamespace::SampleWellKnown.");
SampleWellKnown* proxy =
dynamic_cast<SampleWellKnown*>(RemotingServices::Connect(__typeof(SampleWellKnown), const_cast<String*>(SERVER_URL)));
Console::WriteLine(S"Connected to SampleWellKnown");
// Verifies that the Object* reference is to a transparent proxy.
if (RemotingServices::IsTransparentProxy(proxy))
Console::WriteLine(S"proxy is a reference to a transparent proxy.");
else
Console::WriteLine(S"proxy is not a transparent proxy. This is unexpected.");
// Calls a method on the server Object*.
Console::WriteLine(S"proxy->Add returned {0}.", __box(proxy->Add(2, 3)));
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
See Also
RemotingServices Class | RemotingServices Members | System.Runtime.Remoting Namespace