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

다른 AppDomain개체에 대한 원격 메서드 호출이 수행되면 클래스는 CallContext 원격 호출과 함께 이동하는 인스턴스를 생성합니다 LogicalCallContext . 인터페이스를 ILogicalThreadAffinative 노출하고 이 인터페이스에 CallContext 저장된 개체만 에 있는 외부 AppDomainLogicalCallContext로 전파됩니다. 이 인터페이스를 지원하지 않는 개체는 원격 메서드 호출이 있는 인스턴스에서 LogicalCallContext 전송되지 않습니다.

메모

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

메모

이 클래스는 링크 요청을 만듭니다. 직접 호출자에게 인프라 권한이 없는 경우 A SecurityException 가 throw됩니다.

속성

Name Description
HostContext

현재 스레드와 연결된 호스트 컨텍스트를 가져오거나 설정합니다.

메서드

Name Description
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)

적용 대상

추가 정보