TrackingServices 클래스

정의

추적 처리기 목록을 등록하거나 등록 취소하고 가져오는 방법을 제공합니다.

public ref class TrackingServices
public class TrackingServices
[System.Runtime.InteropServices.ComVisible(true)]
public class TrackingServices
[System.Runtime.InteropServices.ComVisible(true)]
[System.Security.SecurityCritical]
public class TrackingServices
type TrackingServices = class
[<System.Runtime.InteropServices.ComVisible(true)>]
type TrackingServices = class
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Security.SecurityCritical>]
type TrackingServices = class
Public Class TrackingServices
상속
TrackingServices
특성

예제

다음 코드 예제에서는 메서드를 사용 하는 방법을 보여 줍니다는 TrackingServices 클래스를 등록 및 추적 처리기의 등록을 취소 합니다.

다음 코드 예제에는 추적 처리기를 구현 하는 방법을 보여 줍니다.

using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Services;

// Intercept marshal, unmarshal, and disconnect events for an object.
public class TrackingHandler : ITrackingHandler
{
    // Called when the tracked object is marshaled.

    public void MarshaledObject(Object obj, ObjRef objRef)
    {
        // Notify the user of the marshal event.
        Console.WriteLine("Tracking: An instance of {0} was marshaled.", 
            obj.ToString());

        // Print the channel information.
        if (objRef.ChannelInfo != null)
        {
            // Iterate over ChannelData.
            foreach(object data in objRef.ChannelInfo.ChannelData)
            {
                if (data is ChannelDataStore)
                {
                    // Print the URIs from the ChannelDataStore objects.
                    string[] uris = ((ChannelDataStore)data).ChannelUris;
                    foreach(string uri in uris)
                        Console.WriteLine("ChannelUri: " + uri);
                }
            }
        }

        // Print the envoy information.
        if (objRef.EnvoyInfo != null)
            Console.WriteLine("EnvoyInfo: " + objRef.EnvoyInfo.ToString());

        // Print the type information.
        if (objRef.TypeInfo != null)
        {
            Console.WriteLine("TypeInfo: " + objRef.TypeInfo.ToString());
            Console.WriteLine("TypeName: " + objRef.TypeInfo.TypeName);
        }

        // Print the URI.
        if (objRef.URI != null)
            Console.WriteLine("URI: " + objRef.URI.ToString());
    }

    // Called when the tracked object is unmarshaled.
    public void UnmarshaledObject(Object obj, ObjRef objRef)
    {
        Console.WriteLine("Tracking: An instance of {0} was unmarshaled.", 
            obj.ToString());
    }

    // Called when the tracked object is disconnected.
    public void DisconnectedObject(Object obj)
    {
        Console.WriteLine("Tracking: An instance of {0} was disconnected.", 
            obj.ToString());
    }
}

다음 코드 예제에는 서버에서이 클래스를 구현 하는 방법을 보여 줍니다.

using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Services;

public class Server
{
    public static void Main(string[] args)
    {
        // Register the TCP channel.
        TcpChannel channel = new TcpChannel(1234);
        ChannelServices.RegisterChannel(channel);

        // Register a tracking handler.
        ITrackingHandler handler1 = new TrackingHandler();
        TrackingServices.RegisterTrackingHandler(handler1);

        // Register a second handler.
        ITrackingHandler handler2 = new TrackingHandler();
        TrackingServices.RegisterTrackingHandler(handler2);

        // Get the number of currently registered handlers.
        Console.WriteLine("Registered tracking handlers: " + 
            TrackingServices.RegisteredHandlers.Length);

        // Remove the tracking handler from the registered handlers.
        TrackingServices.UnregisterTrackingHandler(handler2);
        Console.WriteLine("Registered tracking handlers: " + 
            TrackingServices.RegisteredHandlers.Length);

        // Create and marshal an object for remote invocation.
        RemoteService service = new RemoteService();
        ObjRef obj = RemotingServices.Marshal(service, "TcpService");

        // Wait for the user prompt.
        Console.WriteLine("\r\nPress ENTER to unmarshal the object.");
        Console.ReadLine();

        // Unmarshal the object.
        RemotingServices.Unmarshal(obj);

        // Wait for the user prompt.
        Console.WriteLine("Press ENTER to disconnect the object.");
        Console.ReadLine();

        // Disconnect the object.
        RemotingServices.Disconnect(service);
    }
}

다음 코드 예제에서는 앞의 코드 예제에서 서버에 대 한 클라이언트에서이 클래스를 구현 하는 방법을 보여 줍니다.

using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

public class Client
{
    public static void Main(string[] args)
    {
        // Register the TCP channel.
        ChannelServices.RegisterChannel(new TcpChannel());

        // Register the client for the remote object.
        WellKnownClientTypeEntry remoteType = new WellKnownClientTypeEntry(
            typeof(RemoteService),"tcp://localhost:1234/TcpService");
        RemotingConfiguration.RegisterWellKnownClientType(remoteType);

        // Create an instance of the remote object.
        RemoteService service = new RemoteService(); 

        // Invoke a method on the remote object.
        service.Hello("world");
        Console.WriteLine("Hello invoked on server.");
    }
}

다음 코드 예제는 서버와 클라이언트에서 사용 되는 원격 개체를 보여 줍니다.

using System;

// Remote object.
public class RemoteService : MarshalByRefObject
{
    private DateTime startTime;

    public RemoteService()
    {
        // Notify the user that the constructor was invoked.
        Console.WriteLine("Constructor invoked.");
        startTime = DateTime.Now;
    }

    ~RemoteService()
    {
        // Notify the user that the finalizer was invoked.
        TimeSpan elapsedTime = 
            new TimeSpan(DateTime.Now.Ticks - startTime.Ticks);
        Console.WriteLine("Finalizer invoked after " + 
            elapsedTime.ToString() + " seconds.");
    }

    public void Hello(string name)
    {
        // Print a simple message.
        Console.WriteLine("Hello, " + name);
    }
}

설명

추적 처리기는 구현 하는 개체는 ITrackingHandler 해야 공지 하도록 원격 인프라 마샬링, 역마샬링, 또는 개체 또는 프록시 연결을 끊습니다 때마다 나타내는 인터페이스입니다. 등록 된 모든 개체 TrackingServices 개체나 현재에서 프록시 하는 경우 원격으로 호출 됩니다 AppDomain 마샬링, 역마샬링을 또는 연결이 끊어진 됩니다.

모든 메서드는 TrackingServices 클래스는 정적이 고 현재에서 추적 처리기 작업할 AppDomain합니다.

참고

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

생성자

TrackingServices()

TrackingServices의 인스턴스를 만듭니다.

속성

RegisteredHandlers

현재 TrackingServicesAppDomain로 등록된 추적 처리기의 배열을 가져옵니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
RegisterTrackingHandler(ITrackingHandler)

TrackingServices로 새로운 추적 처리기를 등록합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)
UnregisterTrackingHandler(ITrackingHandler)

TrackingServices에서 지정된 추적 처리기 등록을 취소합니다.

적용 대상

추가 정보