CallContext クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
実行コード パスに含まれる一連のプロパティを提供します。 このクラスは継承できません。
public ref class CallContext sealed
[System.Serializable]
public sealed class CallContext
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class CallContext
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Security.SecurityCritical]
public sealed class CallContext
[<System.Serializable>]
type CallContext = class
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type CallContext = class
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Security.SecurityCritical>]
type CallContext = class
Public NotInheritable Class CallContext
- 継承
-
CallContext
- 属性
例
次のコード例は、 CallContext クラスを使用して、 プリンシパル オブジェクトと ID オブジェクトを 識別のためにリモートの場所に送信する方法を示しています。 このサンプルで使用する LogicalCallContextData クラスのコードを表示するには、 ILogicalThreadAffinative インターフェイスの例を参照してください。 このサンプルで使用する HelloServiceClass クラスのコードを表示するには、 GetData メソッドの例を参照してください。 このサンプルで使用するサーバー クラスのコードを表示するには、 RegisterActivatedServiceType クラスの例を参照してください。
#using <system.dll>
#using <system.runtime.remoting.dll>
#using <service.dll>
using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Tcp;
using namespace System::Runtime::Remoting::Messaging;
using namespace System::Security::Principal;
int main()
{
GenericIdentity^ ident = gcnew GenericIdentity( "Bob" );
array<String^>^id = gcnew array<String^>(1);
id[ 0 ] = "Level1";
GenericPrincipal^ prpal = gcnew GenericPrincipal( ident,id );
LogicalCallContextData ^ data = gcnew LogicalCallContextData( prpal );
//Enter data into the CallContext
CallContext::SetData( "test data", data );
Console::WriteLine( data->numOfAccesses );
ChannelServices::RegisterChannel( gcnew TcpChannel );
RemotingConfiguration::RegisterActivatedClientType( HelloServiceClass::typeid, "tcp://localhost:8082" );
HelloServiceClass ^ service = gcnew HelloServiceClass;
if ( service == nullptr )
{
Console::WriteLine( "Could not locate server." );
return 0;
}
// call remote method
Console::WriteLine();
Console::WriteLine( "Calling remote Object*" );
Console::WriteLine( service->HelloMethod( "Caveman" ) );
Console::WriteLine( service->HelloMethod( "Spaceman" ) );
Console::WriteLine( service->HelloMethod( "Bob" ) );
Console::WriteLine( "Finished remote Object* call" );
Console::WriteLine();
//Extract the returned data from the call context
LogicalCallContextData ^ returnedData = static_cast<LogicalCallContextData ^>(CallContext::GetData( "test data" ));
Console::WriteLine( data->numOfAccesses );
Console::WriteLine( returnedData->numOfAccesses );
return 0;
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Messaging;
using System.Security.Principal;
using System.Security.Permissions;
public class ClientClass {
public static void Main() {
GenericIdentity ident = new GenericIdentity("Bob");
GenericPrincipal prpal = new GenericPrincipal(ident,
new string[] {"Level1"});
LogicalCallContextData data = new LogicalCallContextData(prpal);
//Enter data into the CallContext
CallContext.SetData("test data", data);
Console.WriteLine(data.numOfAccesses);
ChannelServices.RegisterChannel(new TcpChannel());
RemotingConfiguration.RegisterActivatedClientType(typeof(HelloServiceClass),
"tcp://localhost:8082");
HelloServiceClass service = new HelloServiceClass();
if(service == null) {
Console.WriteLine("Could not locate server.");
return;
}
// call remote method
Console.WriteLine();
Console.WriteLine("Calling remote object");
Console.WriteLine(service.HelloMethod("Caveman"));
Console.WriteLine(service.HelloMethod("Spaceman"));
Console.WriteLine(service.HelloMethod("Bob"));
Console.WriteLine("Finished remote object call");
Console.WriteLine();
//Extract the returned data from the call context
LogicalCallContextData returnedData =
(LogicalCallContextData)CallContext.GetData("test data");
Console.WriteLine(data.numOfAccesses);
Console.WriteLine(returnedData.numOfAccesses);
}
}
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp
Imports System.Runtime.Remoting.Messaging
Imports System.Security.Principal
Imports System.Security.Permissions
Public Class ClientClass
<PermissionSet(SecurityAction.LinkDemand)> _
Public Shared Sub Main()
Dim ident As New GenericIdentity("Bob")
Dim prpal As New GenericPrincipal(ident, New String() {"Level1"})
Dim data As New LogicalCallContextData(prpal)
'Enter data into the CallContext
CallContext.SetData("test data", data)
Console.WriteLine(data.numOfAccesses)
ChannelServices.RegisterChannel(New TcpChannel())
RemotingConfiguration.RegisterActivatedClientType(GetType(HelloServiceClass), "tcp://localhost:8082")
Dim service As New HelloServiceClass()
If service Is Nothing Then
Console.WriteLine("Could not locate server.")
Return
End If
' call remote method
Console.WriteLine()
Console.WriteLine("Calling remote object")
Console.WriteLine(service.HelloMethod("Caveman"))
Console.WriteLine(service.HelloMethod("Spaceman"))
Console.WriteLine(service.HelloMethod("Bob"))
Console.WriteLine("Finished remote object call")
Console.WriteLine()
'Extract the returned data from the call context
Dim returnedData As LogicalCallContextData = CType(CallContext.GetData("test data"), LogicalCallContextData)
Console.WriteLine(data.numOfAccesses)
Console.WriteLine(returnedData.numOfAccesses)
End Sub
End Class
注釈
CallContext は、メソッド呼び出し用の Thread Local Storage に似た特殊なコレクション オブジェクトであり、実行の各論理スレッドに固有のデータ スロットを提供します。 スロットは、他の論理スレッド上の呼び出しコンテキスト間で共有されません。 オブジェクトは、実行コード パスを移動してバックアップする CallContext に追加し、パスに沿ってさまざまなオブジェクトによって調べることができます。
別の AppDomain内のオブジェクトに対してリモート メソッド呼び出しが行われると、 CallContext クラスはリモート呼び出しと共に移動する LogicalCallContext インスタンスを生成します。 ILogicalThreadAffinative インターフェイスを公開し、CallContextに格納されているオブジェクトのみが、LogicalCallContextのAppDomainの外部に伝達されます。 このインターフェイスをサポートしていないオブジェクトは、リモート メソッド呼び出しを使用 LogicalCallContext インスタンスでは送信されません。
注
CallContext内のすべてのメソッドは静的であり、現在のThreadの呼び出しコンテキストで動作します。
注
このクラスは、リンク要求を行います。 直接呼び出し元にインフラストラクチャアクセス許可がない場合、 SecurityException がスローされます。
プロパティ
| 名前 | 説明 |
|---|---|
| HostContext |
現在のスレッドに関連付けられているホスト コンテキストを取得または設定します。 |
メソッド
| 名前 | 説明 |
|---|---|
| Equals(Object) |
指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。 (継承元 Object) |
| FreeNamedDataSlot(String) |
指定した名前のデータ スロットを空にします。 |
| GetData(String) |
指定した名前のオブジェクトを CallContextから取得します。 |
| GetHashCode() |
既定のハッシュ関数として機能します。 (継承元 Object) |
| GetHeaders() |
メソッド呼び出しと共に送信されるヘッダーを返します。 |
| GetType() |
現在のインスタンスの Type を取得します。 (継承元 Object) |
| LogicalGetData(String) |
論理呼び出しコンテキストから、指定した名前のオブジェクトを取得します。 |
| LogicalSetData(String, Object) |
指定したオブジェクトを論理呼び出しコンテキストに格納し、指定した名前に関連付けます。 |
| MemberwiseClone() |
現在の Objectの簡易コピーを作成します。 (継承元 Object) |
| SetData(String, Object) |
指定したオブジェクトを格納し、指定した名前に関連付けます。 |
| SetHeaders(Header[]) |
メソッド呼び出しと共に送信されるヘッダーを設定します。 |
| ToString() |
現在のオブジェクトを表す文字列を返します。 (継承元 Object) |