RemotingServices.Connect 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
為已知物件建立 Proxy。
多載
Connect(Type, String) |
為已知物件建立 Proxy,指定 Type 和 URL。 |
Connect(Type, String, Object) |
為已知物件建立 Proxy,指定 Type、URL 和通道特定的資料。 |
Connect(Type, String)
為已知物件建立 Proxy,指定 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
參數
- url
- String
伺服器類別的 URL。
傳回
遠端物件的 Proxy,指向指定已知物件所服務的端點。
- 屬性
例外狀況
立即呼叫端沒有組態遠端型別和通道的權限。
範例
下列程式碼範例示範如何使用 Connect 方法來建立已知物件的 Proxy。
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))
備註
傳回的 Proxy 物件指向指定之已知物件所提供的端點。 在 Proxy 上呼叫 方法之前,不會透過網路傳送任何訊息。
適用於
Connect(Type, String, Object)
為已知物件建立 Proxy,指定 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
參數
- url
- String
已知物件的 URL。
- data
- Object
通道特定的資料。 可以是 null
。
傳回
Proxy,指向要求的已知物件所服務的端點。
- 屬性
例外狀況
立即呼叫端沒有組態遠端型別和通道的權限。
備註
傳回的 Proxy 物件指向指定之已知物件所提供的端點。 在 Proxy 上呼叫 方法之前,不會透過網路傳送任何訊息。
物件 data
用來將資訊傳達給通道,並傳遞至 IChannelSender.CreateMessageSink 方法。