RemotingConfiguration.RegisterWellKnownServiceType 메서드

정의

개체 Type을 잘 알려진 형식(SingleCall 또는 Singleton)으로 서비스 쪽에 등록합니다.

오버로드

RegisterWellKnownServiceType(WellKnownServiceTypeEntry)

제공된 Type에 기록된 개체 WellKnownServiceTypeEntry을 잘 알려진 형식으로 서비스 쪽에 등록합니다.

RegisterWellKnownServiceType(Type, String, WellKnownObjectMode)

지정된 매개 변수를 사용하여 Type의 새 인스턴스를 초기화하여 개체 WellKnownServiceTypeEntry을 서비스 쪽에 등록합니다.

RegisterWellKnownServiceType(WellKnownServiceTypeEntry)

제공된 Type에 기록된 개체 WellKnownServiceTypeEntry을 잘 알려진 형식으로 서비스 쪽에 등록합니다.

public:
 static void RegisterWellKnownServiceType(System::Runtime::Remoting::WellKnownServiceTypeEntry ^ entry);
public static void RegisterWellKnownServiceType (System.Runtime.Remoting.WellKnownServiceTypeEntry entry);
static member RegisterWellKnownServiceType : System.Runtime.Remoting.WellKnownServiceTypeEntry -> unit
Public Shared Sub RegisterWellKnownServiceType (entry As WellKnownServiceTypeEntry)

매개 변수

entry
WellKnownServiceTypeEntry

잘 알려진 형식에 대한 구성 설정입니다.

예외

호출 스택의 상위 호출자 중 하나 이상에게 원격 형식 및 채널을 구성하기 위한 권한이 없는 경우

예제

#using <system.dll>
#using <system.runtime.remoting.dll>

using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Http;
using namespace System::Runtime::Remoting::Messaging;
using namespace System::Runtime::Serialization;

public ref class RemoteObject: public MarshalByRefObject
{
public:
   void Method1( LocalObject^ param )
   {
      Console::WriteLine( "Invoked: Method1( {0})", param );
   }
};

int main()
{
   ChannelServices::RegisterChannel( gcnew HttpChannel( 8090 ) );
   WellKnownServiceTypeEntry^ wkste = gcnew WellKnownServiceTypeEntry( RemoteObject::typeid,"RemoteObject",WellKnownObjectMode::Singleton );
   RemotingConfiguration::RegisterWellKnownServiceType( wkste );
   RemoteObject^ RObj = dynamic_cast<RemoteObject^>(Activator::GetObject( RemoteObject::typeid, "http://localhost:8090/RemoteObject" ));
   LocalObject^ LObj = gcnew LocalObject;
   RObj->Method1( LObj );
   Console::WriteLine( "Press Return to exit..." );
   Console::ReadLine();
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Serialization;
using System.Security.Permissions;

public class ObjRefExample {

   public static void Main() {

      ChannelServices.RegisterChannel(new HttpChannel(8090));

      WellKnownServiceTypeEntry wkste =
         new WellKnownServiceTypeEntry(typeof(RemoteObject),
                                       "RemoteObject",
                                       WellKnownObjectMode.Singleton);

      RemotingConfiguration.RegisterWellKnownServiceType( wkste );

      RemoteObject RObj =
         (RemoteObject)Activator.GetObject(typeof(RemoteObject),
                                           "http://localhost:8090/RemoteObject");

      LocalObject LObj = new LocalObject();

      RObj.Method1( LObj );

      Console.WriteLine("Press Return to exit...");
      Console.ReadLine();
   }
}

public class RemoteObject : MarshalByRefObject {

   public void Method1(LocalObject param) {
      Console.WriteLine("Invoked: Method1({0})", param);
   }
}
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Http
Imports System.Runtime.Remoting.Messaging
Imports System.Runtime.Serialization
Imports System.Security.Permissions

' code that drives the example
Public Class ObjRefExample

   <PermissionSet(SecurityAction.LinkDemand)> _
   Public Overloads Shared Sub Main()
      ChannelServices.RegisterChannel(New HttpChannel(8090))

      RemotingConfiguration.RegisterWellKnownServiceType(New WellKnownServiceTypeEntry(GetType(RemoteObject), "RemoteObject", WellKnownObjectMode.Singleton))

      Dim RObj As RemoteObject = CType(Activator.GetObject(GetType(RemoteObject), "http://localhost:8090/RemoteObject"), RemoteObject)
      Dim LObj As New LocalObject()

      RObj.Method1(LObj)

      Console.WriteLine("Press Return to exit...")

      Console.ReadLine()
   End Sub

End Class


' a simple remote object
<PermissionSet(SecurityAction.Demand, Name:="FullTrust")> _
Public Class RemoteObject
   Inherits MarshalByRefObject

   Public Sub Method1(ByVal param As LocalObject)
       Console.WriteLine("Invoked: Method1({0})", param)
   End Sub

End Class

설명

등록된 잘 알려진 개체의 URI를 알고 있는 모든 클라이언트는 선호하는 ChannelServices채널을 등록하고 호출 new 또는 메서드를 통해 개체를 활성화하여 개체에 대한 프록시를 Activator.GetObject 가져올 수 있습니다. 잘 알려진 개체 new를 활성화하려면 먼저 메서드를 사용하여 클라이언트에 잘 알려진 개체 형식을 RegisterWellKnownClientType 등록해야 합니다. 메서드를 RegisterWellKnownClientType 호출하면 원격 인프라에 원격 개체의 위치가 제공되므로 키워드가 원격 개체를 new 만들 수 있습니다. 반면에 이 메서드를 사용하여 Activator.GetObject 잘 알려진 개체를 활성화하는 경우 개체의 URL을 인수로 제공해야 하므로 클라이언트 쪽에 사전 등록이 필요하지 않습니다.

호출이 서버에 도착하면 .NET Framework 메시지에서 URI를 추출하고 원격 테이블을 검사하여 URI와 일치하는 개체에 대한 참조를 찾은 다음 필요한 경우 개체를 인스턴스화하여 메서드 호출을 개체에 전달합니다. 개체가 등록 SingleCall되면 메서드 호출이 완료된 후 제거됩니다. 호출된 각 메서드에 대해 개체의 새 인스턴스가 만들어집니다. 유일한 차이점은 Activator.GetObject new 전자에서 URL을 매개 변수로 지정할 수 있고 후자는 구성에서 URL을 가져온다는 것입니다.

원격 개체 자체는 등록 프로세스에 의해 인스턴스화되지 않습니다. 이 클라이언트 개체에서 메서드를 호출 하려고 할 때 발생 하거나 클라이언트 쪽에서 개체를 활성화 합니다.

잘 알려진 개체에 대한 자세한 설명은 서버 정품 인증을 참조하세요.

추가 정보

적용 대상

RegisterWellKnownServiceType(Type, String, WellKnownObjectMode)

지정된 매개 변수를 사용하여 Type의 새 인스턴스를 초기화하여 개체 WellKnownServiceTypeEntry을 서비스 쪽에 등록합니다.

public:
 static void RegisterWellKnownServiceType(Type ^ type, System::String ^ objectUri, System::Runtime::Remoting::WellKnownObjectMode mode);
public static void RegisterWellKnownServiceType (Type type, string objectUri, System.Runtime.Remoting.WellKnownObjectMode mode);
static member RegisterWellKnownServiceType : Type * string * System.Runtime.Remoting.WellKnownObjectMode -> unit
Public Shared Sub RegisterWellKnownServiceType (type As Type, objectUri As String, mode As WellKnownObjectMode)

매개 변수

type
Type

개체 Type입니다.

objectUri
String

개체 URL입니다.

mode
WellKnownObjectMode

등록 중인 잘 알려진 개체 형식의 활성화 모드입니다. WellKnownObjectMode을 참조하십시오.

예외

호출 스택의 상위 호출자 중 하나 이상에게 원격 형식 및 채널을 구성하기 위한 권한이 없는 경우

예제

다음 코드 예제에서는 서버에서 개체 형식을 잘 알려진 개체 형식으로 등록하는 방법을 보여 줍니다. 제공된 서버 코드에 해당하는 클라이언트 코드는 메서드의 예제를 RegisterWellKnownClientType 참조하세요.

#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;
int main()
{
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

public class ServerClass {

    public static void Main()  {
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp


Public Class ServerClass
   
   Public Shared Sub Main()
ChannelServices::RegisterChannel( gcnew TcpChannel( 8082 ) );
RemotingConfiguration::ApplicationName = "HelloServiceApplication";
RemotingConfiguration::RegisterWellKnownServiceType( HelloService::typeid,
                                                     "MyUri",
                                                     WellKnownObjectMode::SingleCall );
ChannelServices.RegisterChannel(new TcpChannel(8082));

RemotingConfiguration.ApplicationName = "HelloServiceApplication";

RemotingConfiguration.RegisterWellKnownServiceType( typeof(HelloService),
                                                    "MyUri",
                                                    WellKnownObjectMode.SingleCall
                                                  );
ChannelServices.RegisterChannel(New TcpChannel(8082))

RemotingConfiguration.ApplicationName = "HelloServiceApplication"

RemotingConfiguration.RegisterWellKnownServiceType(GetType(HelloService), "MyUri", WellKnownObjectMode.SingleCall)
   Console::WriteLine( "Press enter to stop this process." );
   Console::ReadLine();
   return 0;
}

        Console.WriteLine("Press enter to stop this process.");
        Console.ReadLine();
    }
}

      Console.WriteLine("Press enter to stop this process.")
      Console.ReadLine()

   End Sub

End Class

다음 코드 예제에서는 위의 샘플 코드에 등록된 서비스 개체를 보여줍니다.

#using <system.dll>

using namespace System;
public ref class HelloService: public MarshalByRefObject
{
private:
   static int n_instances;

public:
   HelloService()
   {
      n_instances++;
      Console::WriteLine( "" );
      Console::WriteLine( "HelloService activated - instance # {0}.", n_instances );
   }

   ~HelloService()
   {
      Console::WriteLine( "HelloService instance {0} destroyed.", n_instances );
      n_instances--;
   }

   String^ HelloMethod( String^ name )
   {
      Console::WriteLine( "HelloMethod called on HelloService instance {0}.", n_instances );
      return String::Format( "Hi there {0}.", name );
   }

};
using System;

public class HelloService : MarshalByRefObject {

    static int n_instances;

    public HelloService() {
        n_instances++;
        Console.WriteLine("");
        Console.WriteLine("HelloService activated - instance # {0}.", n_instances);
    }

    ~HelloService()  {
        Console.WriteLine("HelloService instance {0} destroyed.", n_instances);
        n_instances--;
    }

    public String HelloMethod(String name)  {

        Console.WriteLine("HelloMethod called on HelloService instance {0}.", n_instances);
        return "Hi there " + name + ".";
    }
}
Public Class HelloService
   Inherits MarshalByRefObject
   
   Private Shared n_instances As Integer
     
   Public Sub New()
      n_instances += 1
      Console.WriteLine("")
      Console.WriteLine("HelloService activated - instance # {0}.", n_instances)
   End Sub
   
   
   Protected Overrides Sub Finalize()
      Console.WriteLine("HelloService instance {0} destroyed.", n_instances)
      n_instances -= 1
      MyBase.Finalize()
   End Sub
   
   
   Public Function HelloMethod(name As [String]) As [String]
      Console.WriteLine("HelloMethod called on HelloService instance {0}.", n_instances)
      Return "Hi there " + name + "."
   End Function 'HelloMethod

End Class

설명

등록된 잘 알려진 개체의 URI를 알고 있는 모든 클라이언트는 선호하는 ChannelServices채널을 등록하고 호출 new 또는 메서드를 통해 개체를 활성화하여 개체에 대한 프록시를 Activator.GetObject 가져올 수 있습니다. 잘 알려진 개체 new를 활성화하려면 먼저 메서드를 사용하여 클라이언트에 잘 알려진 개체 형식을 RegisterWellKnownClientType 등록해야 합니다. 메서드를 RegisterWellKnownClientType 호출하면 원격 인프라에 원격 개체의 위치가 제공되므로 키워드가 원격 개체를 new 만들 수 있습니다. 반면에 이 메서드를 사용하여 Activator.GetObject 잘 알려진 개체를 활성화하는 경우 개체의 URL을 인수로 제공해야 하므로 클라이언트 쪽에 사전 등록이 필요하지 않습니다.

호출이 서버에 도착하면 .NET Framework 메시지에서 URI를 추출하고 원격 테이블을 검사하여 URI와 일치하는 개체에 대한 참조를 찾은 다음 필요한 경우 개체를 인스턴스화하여 메서드 호출을 개체에 전달합니다. 개체가 등록 SingleCall되면 메서드 호출이 완료된 후 제거됩니다. 호출된 각 메서드에 대해 개체의 새 인스턴스가 만들어집니다. 유일한 차이점은 Activator.GetObject new 전자에서 URL을 매개 변수로 지정할 수 있고 후자는 구성에서 URL을 가져온다는 것입니다.

원격 개체 자체는 등록 프로세스에 의해 인스턴스화되지 않습니다. 이 클라이언트 개체에서 메서드를 호출 하려고 할 때 발생 하거나 클라이언트 쪽에서 개체를 활성화 합니다.

잘 알려진 개체에 대한 자세한 설명은 서버 정품 인증을 참조하세요.

추가 정보

적용 대상