次の方法で共有


RemotingServices.Connect メソッド (Type, String)

Type および URL を指定して、既知のオブジェクトのプロキシを作成します。

Overloads Public Shared Function Connect( _
   ByVal classToProxy As Type, _   ByVal url As String _) As Object
[C#]
public static object Connect(TypeclassToProxy,stringurl);
[C++]
public: static Object* Connect(Type* classToProxy,String* url);
[JScript]
public static function Connect(
   classToProxy : Type,url : String) : Object;

パラメータ

  • classToProxy
    サーバー エンドにある接続する既知のオブジェクトの Type
  • url
    サーバー クラスの URL。

戻り値

指定した既知のオブジェクトによって提供されたエンドポイントを指す、リモート オブジェクトへのプロキシ。

例外

例外の種類 条件
SecurityException 直前の呼び出し元に、リモート処理の型とチャネルを構成するためのアクセス許可がありません。

解説

返されたプロキシ オブジェクトは、指定した既知のオブジェクトによって提供されたエンドポイントを指します。プロキシでメソッドが呼び出されるまで、ネットワーク上でメッセージは送信されません。

使用例

[Visual Basic, C#, C++] Connect メソッドを使用して、プロキシを既知のオブジェクトに対して作成する方法の例を次に示します。

 
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] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

.NET Framework セキュリティ:

参照

RemotingServices クラス | RemotingServices メンバ | System.Runtime.Remoting 名前空間 | RemotingServices.Connect オーバーロードの一覧