CallContext 클래스

정의

실행 코드 경로로 전달된 속성 집합을 제공합니다. 이 클래스는 상속될 수 없습니다.

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은 메서드 호출을 위한 스레드 로컬 스토리지와 유사한 특수 컬렉션 개체이며 각 논리 스레드 실행에 고유한 데이터 슬롯을 제공합니다. 슬롯 논리 다른 스레드에서 호출 컨텍스트 간에 공유 되지 않습니다. 실행 코드 경로를 아래로 이동하고 백업할 CallContext 때 개체를 추가할 수 있으며 경로를 따라 다양한 개체에서 검사할 수 있습니다.

다른 AppDomain개체에 대한 원격 메서드 호출이 수행되면 클래스는 CallContext 원격 호출과 함께 이동하는 인스턴스를 생성합니다 LogicalCallContext . 개체만 해당 노출 합니다 ILogicalThreadAffinative 인터페이스와 저장 됩니다는 CallContext 전파 됩니다는 AppDomain 에서 LogicalCallContext. 이 인터페이스를 지원 하지 않는 개체에 전송 되지 않은 LogicalCallContext 원격 메서드 호출을 사용 하 여 인스턴스.

참고

모든 CallContext 메서드는 정적이며 현재 Thread호출 컨텍스트에서 작동합니다.

참고

이 클래스에는 링크 요청을 만듭니다. 즉시 호출자에게 인프라 권한이 없는 경우 A SecurityException 가 throw됩니다. 참조 링크 요구가 자세한 내용은 합니다.

속성

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)

적용 대상

추가 정보