ObjRef ObjRef ObjRef ObjRef Class

정의

원격 개체와 통신하려면 프록시를 생성하는 데 필요한 모든 관련 정보를 저장합니다.Stores all relevant information required to generate a proxy in order to communicate with a remote object.

public ref class ObjRef : System::Runtime::Serialization::IObjectReference, System::Runtime::Serialization::ISerializable
[System.Runtime.InteropServices.ComVisible(true)]
[System.Security.SecurityCritical]
[System.Serializable]
public class ObjRef : System.Runtime.Serialization.IObjectReference, System.Runtime.Serialization.ISerializable
type ObjRef = class
    interface IObjectReference
    interface ISerializable
Public Class ObjRef
Implements IObjectReference, ISerializable
상속
ObjRefObjRefObjRefObjRef
특성
구현

예제

다음 코드 예제에서는 사용자 지정 사용을 보여 줍니다. ObjRef합니다.The following code example demonstrates the use of a custom ObjRef. 사용자 지정 테스트 하는 활성화 코드를 보려면 ObjRef에 대 한 예제를 참조 하세요.를 RegisterWellKnownServiceType 메서드.To view the activation code that tests the custom ObjRef, see the example for the RegisterWellKnownServiceType method.

// a custom ObjRef class that outputs its status
[System::Security::Permissions::SecurityPermissionAttribute(
   System::Security::Permissions::SecurityAction::Demand, 
   Flags=System::Security::Permissions::SecurityPermissionFlag::SerializationFormatter)]
[System::Security::Permissions::SecurityPermissionAttribute
(System::Security::Permissions::SecurityAction::Demand, 
Flags=System::Security::Permissions::SecurityPermissionFlag::Infrastructure)]	
[System::Security::Permissions::SecurityPermissionAttribute
(System::Security::Permissions::SecurityAction::InheritanceDemand, 
Flags=System::Security::Permissions::SecurityPermissionFlag::Infrastructure)]
public ref class MyObjRef: public ObjRef
{
private:

   // only instantiate using marshaling or deserialization
   MyObjRef(){}

public:
   MyObjRef( MarshalByRefObject^ o, Type^ t )
      : ObjRef( o, t )
   {
      Console::WriteLine( "Created MyObjRef." );
      ORDump();
   }

   MyObjRef( SerializationInfo^ i, StreamingContext c )
      : ObjRef( i, c )
   {
      Console::WriteLine( "Deserialized MyObjRef." );
   }

   virtual void GetObjectData( SerializationInfo^ s, StreamingContext c ) override
   {
      // After calling the base method, change the type from ObjRef to MyObjRef
      ObjRef::GetObjectData( s, c );
      s->SetType( GetType() );
      Console::WriteLine( "Serialized MyObjRef." );
   }

   virtual Object^ GetRealObject( StreamingContext context ) override
   {
      if ( IsFromThisAppDomain() || IsFromThisProcess() )
      {
         Console::WriteLine( "Returning actual Object^ referenced by MyObjRef." );
         return ObjRef::GetRealObject( context );
      }
      else
      {
         Console::WriteLine( "Returning proxy to remote Object^." );
         return RemotingServices::Unmarshal( this );
      }
   }

   void ORDump()
   {
      Console::WriteLine( " --- Reporting MyObjRef Info --- " );
      Console::WriteLine( "Reference to {0}.", TypeInfo->TypeName );
      Console::WriteLine( "URI is {0}.", URI );
      Console::WriteLine( "\nWriting EnvoyInfo: " );
      if ( EnvoyInfo != nullptr )
      {
         IMessageSink^ EISinks = EnvoyInfo->EnvoySinks;
         while ( EISinks != nullptr )
         {
            Console::WriteLine( "\tSink: {0}", EISinks );
            EISinks = EISinks->NextSink;
         }
      }
      else
            Console::WriteLine( "\t {no sinks}" );

      Console::WriteLine( "\nWriting ChannelInfo: " );
      for ( int i = 0; i < ChannelInfo->ChannelData->Length; i++ )
         Console::WriteLine( "\tChannel: {0}", ChannelInfo->ChannelData[ i ] );
      Console::WriteLine( " ----------------------------- " );
   }

};

// a class that uses MyObjRef
public ref class LocalObject: public MarshalByRefObject
{
public:

   // overriding CreateObjRef will allow us to return a custom ObjRef
   [System::Security::Permissions::SecurityPermissionAttribute
   (System::Security::Permissions::SecurityAction::LinkDemand,
   Flags=System::Security::Permissions::SecurityPermissionFlag::Infrastructure)]
   virtual ObjRef^ CreateObjRef( Type^ t ) override
   {
      return gcnew MyObjRef( this,t );
   }
};
// a custom ObjRef class that outputs its status
[PermissionSet(SecurityAction.Demand, Name="FullTrust")]
public class MyObjRef : ObjRef {
   
   // only instantiate using marshaling or deserialization
   private MyObjRef() { }

   public MyObjRef(MarshalByRefObject o, Type t) : base(o, t)  {
      Console.WriteLine("Created MyObjRef.");
      ORDump();
   }

   public MyObjRef(SerializationInfo i, StreamingContext c) : base(i, c) {
      Console.WriteLine("Deserialized MyObjRef.");
   }

   public override void GetObjectData(SerializationInfo s, StreamingContext c) {
      // After calling the base method, change the type from ObjRef to MyObjRef
      base.GetObjectData(s, c);
      s.SetType(GetType());
      Console.WriteLine("Serialized MyObjRef.");
   }

   public override Object GetRealObject(StreamingContext context) {

      if ( IsFromThisAppDomain() || IsFromThisProcess() ) {
         Console.WriteLine("Returning actual object referenced by MyObjRef.");
         return base.GetRealObject(context);
      }
      else {
         Console.WriteLine("Returning proxy to remote object.");
         return RemotingServices.Unmarshal(this);
      }
   }   

   public void ORDump() {

      Console.WriteLine(" --- Reporting MyObjRef Info --- ");
      Console.WriteLine("Reference to {0}.", TypeInfo.TypeName);
      Console.WriteLine("URI is {0}.", URI);
      Console.WriteLine("\nWriting EnvoyInfo: ");

      if ( EnvoyInfo != null) {
         
         IMessageSink EISinks = EnvoyInfo.EnvoySinks;
         while (EISinks != null) {
            Console.WriteLine("\tSink: " + EISinks.ToString());  
            EISinks = EISinks.NextSink;
         }
      }
      else
         Console.WriteLine("\t {no sinks}");

      Console.WriteLine("\nWriting ChannelInfo: ");
      for (int i = 0; i < ChannelInfo.ChannelData.Length; i++)
         Console.WriteLine ("\tChannel: {0}", ChannelInfo.ChannelData[i]);
      Console.WriteLine(" ----------------------------- ");
   }
}


// a class that uses MyObjRef
[PermissionSet(SecurityAction.Demand, Name="FullTrust")]
public class LocalObject : MarshalByRefObject {
   // overriding CreateObjRef will allow us to return a custom ObjRef
   public override ObjRef CreateObjRef(Type t) {
      return new MyObjRef(this, t);
   }
}
' a custom ObjRef class that outputs its status
<PermissionSet(SecurityAction.Demand, Name:="FullTrust")> _
Public Class MyObjRef
   Inherits ObjRef

   ' only instantiate using marshaling or deserialization
   Private Sub New()
   End Sub

   Public Sub New(ByVal o As MarshalByRefObject, ByVal t As Type)
      MyBase.New(o, t)
      Console.WriteLine("Created MyObjRef.")
      ORDump()
   End Sub

   Public Sub New(ByVal i As SerializationInfo, ByVal c As StreamingContext)
      MyBase.New(i, c)
      Console.WriteLine("Deserialized MyObjRef.")
   End Sub

   Public Overrides Sub GetObjectData(ByVal s As SerializationInfo, ByVal c As StreamingContext)
      ' After calling the base method, change the type from ObjRef to MyObjRef
      MyBase.GetObjectData(s, c)
      s.SetType([GetType]())
      Console.WriteLine("Serialized MyObjRef.")
   End Sub

   Public Overrides Function GetRealObject(ByVal context As StreamingContext) As [Object]
      If IsFromThisAppDomain() Or IsFromThisProcess() Then
         Console.WriteLine("Returning actual object referenced by MyObjRef.")
         Return MyBase.GetRealObject(context)
      Else
         Console.WriteLine("Returning proxy to remote object.")
         Return RemotingServices.Unmarshal(Me)
      End If
   End Function

   Public Sub ORDump()
      Console.WriteLine(" --- Reporting MyObjRef Info --- ")
      Console.WriteLine("Reference to {0}.", TypeInfo.TypeName)
      Console.WriteLine("URI is {0}.", URI)

      Console.WriteLine(ControlChars.Cr + "Writing EnvoyInfo: ")
      If Not (EnvoyInfo Is Nothing) Then
         Dim EISinks As IMessageSink = EnvoyInfo.EnvoySinks
         Dim count As Integer = 0
         While Not (EISinks Is Nothing)
            Console.WriteLine(ControlChars.Tab + "Interated through sink #{0}", (count = count + 1))
            EISinks = EISinks.NextSink
         End While
      Else
         Console.WriteLine(ControlChars.Tab + " {no sinks}")
      End If
      Console.WriteLine(ControlChars.Cr + "Writing ChannelInfo: ")
      Dim i As Integer
      For i = 0 To ChannelInfo.ChannelData.Length - 1
         Console.WriteLine(ControlChars.Tab + "Channel: {0}", ChannelInfo.ChannelData(i))
      Next i
      Console.WriteLine(" ----------------------------- ")
   End Sub
   
End Class


' a class that uses MyObjRef
<PermissionSet(SecurityAction.Demand, Name:="FullTrust")> _
Public Class LocalObject
   Inherits MarshalByRefObject

   ' overriding CreateObjRef will allow us to return a custom ObjRef
   Public Overrides Function CreateObjRef(ByVal t As Type) As ObjRef
      Return New MyObjRef(Me, t)
   End Function

End Class

설명

A ObjRef 확장 하는 개체의 직렬화 표현인 MarshalByRefObject (MBR).A ObjRef is a serializable representation of an object that extends MarshalByRefObject (MBR). A ObjRef 간에 개체 참조를 전송 하는 데 사용 되는 AppDomain 경계입니다.A ObjRef is used to transfer an object reference across a AppDomain boundary. 만들기는 ObjRef 에 개체 마샬링 이라고 합니다.Creating a ObjRef for an object is known as marshaling. 만들 수 있습니다는 ObjRef (마샬링을 MarshalByRefObject) 하거나 명시적으로 MBR을 등록 하 여 개체 원격 인프라를 사용 하 여 (참조 RemotingConfigurationRemotingServices.Marshal), 또는 원격 호출 하는 경우 MBR 개체를 매개 변수로 전달 하 여 암시적 개체입니다.You can create a ObjRef (marshal a MarshalByRefObject) either explicitly, by registering the MBR object with the remoting infrastructure (see RemotingConfiguration and RemotingServices.Marshal), or implicitly, by passing an MBR object as a parameter when calling a remote object. Remoting 사용 ObjRef 저장 하 고 모든 관련 정보에 대 한 전송 개체는 MarshalByRefObject 원격 처리 되 고 있습니다.Remoting uses ObjRef objects to store and transmit all the relevant information about the MarshalByRefObject being remoted.

ObjRef 설명 하는 정보를 포함 합니다 Type 및 개체의 클래스 마샬링되, 정확한 위치 및 개체가 위치한 원격 하위 영역에 도달 하는 방법에 대 한 통신 관련 정보입니다.The ObjRef contains information that describes the Type and class of the object being marshaled, its exact location, and communication-related information on how to reach the remoting subdivision where the object is located.

클래스를 구현한 후 MarshalByRefObject 에 마샬링되는 ObjRef 나타내는 다른 프로세스 또는 컴퓨터에서 가능한 경우 다른 애플리케이션 도메인에 채널을 통해 전송 됩니다.After a class implementing MarshalByRefObject is marshaled, the ObjRef that represents it is transferred through a channel into another application domain, possibly in another process or computer. 경우는 ObjRef deserialize 되는 (참조 XML 및 SOAP Serialization) 대상 애플리케이션 도메인의 구문 분석 되어 원격 MBR 개체에 대 한 투명 프록시를 만듭니다.When the ObjRef is deserialized (see XML and SOAP Serialization) in the target application domain, it is parsed to create a transparent proxy for the remote MBR object. 이 작업은 역마샬링 이라고 합니다.This operation is known as unmarshaling.

투명 프록시는 실제 개체는 클라이언트의 공간에 상주 하는 것 처럼 보이게 하는 개체입니다.A transparent proxy is an object that provides the illusion that the actual object resides in the client's space. 원격 인프라를 사용 하 여 실제 개체에 대해 호출을 전달 하 여 달성 합니다.It achieves this by forwarding calls made on it to the real object using the remoting infrastructure. 투명 프록시 형식의 관리 되는 런타임 클래스의 인스턴스 자체는 RealProxy합니다.The transparent proxy is itself housed by an instance of a managed run-time class of type RealProxy. RealProxy 투명 프록시에서 작업을 전달 하는 데 필요한 기능 중 일부를 구현 합니다.The RealProxy implements a part of the functionality needed to forward the operations from the transparent proxy.

모든 원격 하나당에 관계 없이 프록시 개체를 사용할 수는 AppDomain합니다.A proxy object can be used without regard to any remoting subdivisions within a AppDomain. 애플리케이션 프록시 참조 및 개체 참조를 구분 하지 해야 합니다.Applications need not distinguish between proxy references and object references. 그러나 서비스 공급자 정품 인증과 같은 문제를 다루는, 수명 관리와 트랜잭션 해야 이러한 차이점을 확인 합니다.However, service providers dealing with issues such as activation, lifetime management, and transactions need to make such distinctions.

이 클래스는 클래스 수준에서 상속 요청과 링크 요청을 만듭니다.This class makes a link demand and an inheritance demand at the class level. SecurityException 직접 실행 호출자 또는 파생된 클래스 중 하나에 인프라 권한이 없는 경우 throw 됩니다.A SecurityException is thrown when either the immediate caller or the derived class does not have infrastructure permission. 보안 요청에 대 한 자세한 내용은 참조 하세요 링크 요청 하 고 상속 요청합니다.For details about security demands, see Link Demands and Inheritance Demands.

생성자

ObjRef() ObjRef() ObjRef() ObjRef()

기본값을 사용하여 ObjRef 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the ObjRef class with default values.

ObjRef(MarshalByRefObject, Type) ObjRef(MarshalByRefObject, Type) ObjRef(MarshalByRefObject, Type) ObjRef(MarshalByRefObject, Type)

지정된 ObjRef의 지정된 MarshalByRefObject를 참조할 Type 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the ObjRef class to reference a specified MarshalByRefObject of a specified Type.

ObjRef(SerializationInfo, StreamingContext) ObjRef(SerializationInfo, StreamingContext) ObjRef(SerializationInfo, StreamingContext) ObjRef(SerializationInfo, StreamingContext)

serialize된 데이터로부터 ObjRef 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the ObjRef class from serialized data.

속성

ChannelInfo ChannelInfo ChannelInfo ChannelInfo

IChannelInfoObjRef를 가져오거나 설정합니다.Gets or sets the IChannelInfo for the ObjRef.

EnvoyInfo EnvoyInfo EnvoyInfo EnvoyInfo

IEnvoyInfoObjRef를 가져오거나 설정합니다.Gets or sets the IEnvoyInfo for the ObjRef.

TypeInfo TypeInfo TypeInfo TypeInfo

IRemotingTypeInfo에서 설명하는 개체에 대한 ObjRef를 가져오거나 설정합니다.Gets or sets the IRemotingTypeInfo for the object that the ObjRef describes.

URI URI URI URI

특정 개체 인스턴스의 URI를 가져오거나 설정합니다.Gets or sets the URI of the specific object instance.

메서드

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

지정한 개체와 현재 개체가 같은지 여부를 확인합니다.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

기본 해시 함수로 작동합니다.Serves as the default hash function.

(Inherited from Object)
GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext)

현재 SerializationInfo 인스턴스를 serialize하는 데 필요한 데이터를 사용하여 지정된 ObjRef를 채웁니다.Populates a specified SerializationInfo with the data needed to serialize the current ObjRef instance.

GetRealObject(StreamingContext) GetRealObject(StreamingContext) GetRealObject(StreamingContext) GetRealObject(StreamingContext)

ObjRef에서 설명하는 원격 개체에 대한 참조를 반환합니다.Returns a reference to the remote object that the ObjRef describes.

GetType() GetType() GetType() GetType()

현재 인스턴스의 Type을 가져옵니다.Gets the Type of the current instance.

(Inherited from Object)
IsFromThisAppDomain() IsFromThisAppDomain() IsFromThisAppDomain() IsFromThisAppDomain()

현재 ObjRef 인스턴스가 현재 AppDomain에 있는 개체를 참조하는지 여부를 나타내는 부울 값을 반환합니다.Returns a Boolean value that indicates whether the current ObjRef instance references an object located in the current AppDomain.

IsFromThisProcess() IsFromThisProcess() IsFromThisProcess() IsFromThisProcess()

현재 ObjRef 인스턴스가 현재 프로세스에 있는 개체를 참조하는지 여부를 나타내는 부울 값을 반환합니다.Returns a Boolean value that indicates whether the current ObjRef instance references an object located in the current process.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

현재 개체를 나타내는 문자열을 반환합니다.Returns a string that represents the current object.

(Inherited from Object)

보안

SecurityPermission
한 인프라 코드를 사용 하 여 작동 합니다.for operating with infrastructure code. 요청 값: InheritanceDemand; 권한 값: InfrastructureDemand value: InheritanceDemand; Permission Value: Infrastructure

적용 대상

추가 정보