RemotingServices.Connect 方法

定义

为已知对象创建一个代理。

重载

Connect(Type, String)

使用给定的 Type 和 URL,为已知对象创建一个代理。

Connect(Type, String, Object)

使用给定的 Type、URL 和信道特定数据,为已知对象创建一个代理。

Connect(Type, String)

使用给定的 Type 和 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

参数

classToProxy
Type

要连接到的位于服务器端的已知对象的 Type

url
String

服务器类的 URL。

返回

Object

远程对象的代理,指向由指定的已知对象提供的终结点。

属性

例外

直接调用方没有配置远程处理类型和通道的权限。

示例

下面的代码示例演示如何使用 Connect 该方法创建到已知对象的代理。

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))

注解

返回的代理对象指向由指定的已知对象提供的终结点。 在代理上调用方法之前,不会通过网络发送消息。

适用于

Connect(Type, String, Object)

使用给定的 Type、URL 和信道特定数据,为已知对象创建一个代理。

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

参数

classToProxy
Type

要连接到的已知对象的 Type

url
String

已知对象的 URL。

data
Object

信道特定的数据。 可以为 null

返回

Object

指向由所请求的已知对象提供的终结点的代理。

属性

例外

直接调用方没有配置远程处理类型和通道的权限。

注解

返回的代理对象指向由指定的已知对象提供的终结点。 在代理上调用方法之前,不会通过网络发送消息。

data 对象用于将信息传达给通道,并传递给 IChannelSender.CreateMessageSink 该方法。

适用于