語言

RemotingServices.Connect 方法

定義

建立一個知名物件的代理。

多載

名稱 Description
Connect(Type, String)

根據 和 URL,為一個已知物件 Type 建立代理。

Connect(Type, String, Object)

根據 、 、 及通道特定資料,建立一個已知物件 Type的代理。

Connect(Type, String)

根據 和 URL,為一個已知物件 Type 建立代理。

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

伺服器類別的網址。

傳回

指向遠端物件的代理,指向由指定且知名物件服務的端點。

屬性

例外狀況

直接呼叫者無權設定遠端通訊類型與通道。

範例

以下程式碼範例示範如何使用此 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的代理。

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

那個知名物件的網址。

data
Object

頻道專屬資料。 可以是 null。

傳回

一個指向由所請求的已知物件服務端點的代理。

屬性

例外狀況

直接呼叫者無權設定遠端通訊類型與通道。

備註

回傳的代理物件指向由指定且知名物件服務的端點。 在代理伺服器呼叫某方法之前,網路上不會傳送任何訊息。

物件data用於向通道傳遞資訊,並傳遞給方法。IChannelSender.CreateMessageSink

適用於