UrlAttribute Klasa

Definicja

Definiuje atrybut, który może być używany w lokacji wywołania w celu określenia adresu URL, pod którym nastąpi aktywacja. Klasa ta nie może być dziedziczona.

public ref class UrlAttribute sealed : System::Runtime::Remoting::Contexts::ContextAttribute
[System.Serializable]
public sealed class UrlAttribute : System.Runtime.Remoting.Contexts.ContextAttribute
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class UrlAttribute : System.Runtime.Remoting.Contexts.ContextAttribute
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Security.SecurityCritical]
public sealed class UrlAttribute : System.Runtime.Remoting.Contexts.ContextAttribute
[<System.Serializable>]
type UrlAttribute = class
    inherit ContextAttribute
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type UrlAttribute = class
    inherit ContextAttribute
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Security.SecurityCritical>]
type UrlAttribute = class
    inherit ContextAttribute
Public NotInheritable Class UrlAttribute
Inherits ContextAttribute
Dziedziczenie
Atrybuty

Przykłady

Poniższy przykład kodu ilustruje użycie polecenia UrlAttribute w konfigurowaniu komunikacji zdalnie aktywowanej przez klienta. Przykład zawiera trzy części: klienta, serwera i obiektu zdalnego, który jest używany przez klienta i serwer.

Poniższy przykład kodu przedstawia klienta:

#using <System.Runtime.Remoting.dll>
#using <System.dll>
#using "RemoteObject.dll"

using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Activation;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Tcp;

[STAThread]
int main()
{
   
   // Report initial status.
   Console::WriteLine( "Client starting." );
   
   // Register TCP channel.
   ChannelServices::RegisterChannel( gcnew TcpChannel );
   
   // Create UrlAttribute.
   UrlAttribute^ attribute = gcnew UrlAttribute( "tcp://localhost:1234/RemoteApp" );
   Console::WriteLine( "UrlAttribute value: {0}", attribute->UrlValue );
   
   array<Object^>^activationAttributes = {attribute};
   
   // Use UrlAttribute to register for client activated remote object.
   RemotingConfiguration::RegisterActivatedClientType( RemoteObject::typeid, "tcp://localhost:1234/RemoteApp" );
   
   // Activate remote object.
   Console::WriteLine( "Activating remote object." );
   RemoteObject ^ obj = dynamic_cast<RemoteObject^>(Activator::CreateInstance( RemoteObject::typeid, nullptr, activationAttributes ));
   
   // Invoke a method on it.
   Console::WriteLine( "Invoking Hello() on remote object." );
   obj->Hello();
   
   // Inform user of termination.
   Console::WriteLine( "Terminating client." );
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Activation;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

public class Client
{
    [STAThread]
    public static void Main()
    {
        // Report the initial status.
        Console.WriteLine("Starting client.");

        // Register the TCP channel.
        ChannelServices.RegisterChannel(new TcpChannel());

        // Create a url attribute object.
        UrlAttribute attribute =
            new UrlAttribute("tcp://localhost:1234/RemoteApp");
        Console.WriteLine("UrlAttribute value: {0}", attribute.UrlValue);
        object[] activationAttributes = new object[] { attribute };

        // Register the client for the remote object.
        RemotingConfiguration.RegisterActivatedClientType(
            typeof(RemoteObject),
            "tcp://localhost:1234/RemoteApp");

        // Activate the remote object.
        Console.WriteLine("Activating remote object.");
        RemoteObject obj = (RemoteObject) Activator.CreateInstance(
            typeof(RemoteObject), null, activationAttributes);

        // Invoke a method on the remote object.
        Console.WriteLine("Invoking Hello() on remote object.");
        obj.Hello();

        // Inform the user that the program is exiting.
        Console.WriteLine("The client is exiting.");
    }
}

Poniższy przykład kodu przedstawia serwer dla tego klienta:

#using <System.Runtime.Remoting.dll>
#using <System.dll>
#using "RemoteObject.dll"

using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Tcp;

[STAThread]
int main()
{
   
   // Report status to user.
   Console::WriteLine( "Server starting." );
   
   // Register the TCP channel.
   ChannelServices::RegisterChannel( gcnew TcpChannel( 1234 ) );
   
   // Set application name.
   RemotingConfiguration::ApplicationName = "RemoteApp";
   
   // Register object for client activated remoting.
   RemotingConfiguration::RegisterActivatedServiceType( RemoteObject::typeid );
   
   // Wait until termination.
   Console::WriteLine( "Press enter to end." );
   Console::ReadLine();
   Console::WriteLine( "Terminating server." );
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

public class Server
{
    [STAThread]
    public static void Main()
    {
        // Report the status to the user.
        Console.WriteLine("Starting server.");

        // Register the TCP channel.
        ChannelServices.RegisterChannel(new TcpChannel(1234));

        // Set the application name.
        RemotingConfiguration.ApplicationName = "RemoteApp";

        // Register the object for remoting.
        RemotingConfiguration.RegisterActivatedServiceType(
            typeof(RemoteObject));

        // Wait until the user presses ENTER.
        Console.WriteLine("Press ENTER to exit.");
        Console.ReadLine();
        Console.WriteLine("The server is exiting.");
    }
}

Poniższy przykład kodu przedstawia obiekt zdalny używany przez klienta i serwer:

using namespace System;
using namespace System::Security;
using namespace System::Security::Permissions;

[assembly:AllowPartiallyTrustedCallersAttribute];
public ref class RemoteObject: public MarshalByRefObject
{
public:
   RemoteObject()
   {
      
      // Report object construction to server's console.
      Console::WriteLine( "You have called the constructor." );
   }

   void Hello()
   {
      
      // Report method invocation to server's console.
      Console::WriteLine( "You have called Hello()." );
   }

};
using System;
using System.Security;
using System.Security.Permissions;

public class RemoteObject : MarshalByRefObject
{
    public RemoteObject()
    {
        Console.WriteLine("You have called the constructor.");
    }

    public void Hello()
    {
        Console.WriteLine("You have called Hello().");
    }
}

Uwagi

Element UrlAttribute jest przekazywany w tablicy atrybutów aktywacji jako parametr do Activator.CreateInstance podczas tworzenia aktywowanych obiektów za pomocą CreateInstance metody .

Aby uzyskać więcej informacji na temat używania atrybutów, zobacz Atrybuty.

Konstruktory

UrlAttribute(String)

Tworzy nowe wystąpienie klasy UrlAttribute.

Pola

AttributeName

Ten interfejs API obsługuje infrastrukturę produktu i nie jest przeznaczony do użycia bezpośrednio z poziomu kodu.

Wskazuje nazwę atrybutu kontekstu.

(Odziedziczone po ContextAttribute)

Właściwości

Name

Ten interfejs API obsługuje infrastrukturę produktu i nie jest przeznaczony do użycia bezpośrednio z poziomu kodu.

Pobiera nazwę atrybutu kontekstu.

(Odziedziczone po ContextAttribute)
TypeId

Po zaimplementowaniu w klasie pochodnej pobiera unikatowy identyfikator dla tego Attributeelementu .

(Odziedziczone po Attribute)
UrlValue

Pobiera wartość adresu URL elementu UrlAttribute.

Metody

Equals(Object)

Sprawdza, czy określony obiekt odwołuje się do tego samego adresu URL co bieżące wystąpienie.

Freeze(Context)

Ten interfejs API obsługuje infrastrukturę produktu i nie jest przeznaczony do użycia bezpośrednio z poziomu kodu.

Wywoływana, gdy kontekst jest zamrożony.

(Odziedziczone po ContextAttribute)
GetHashCode()

Zwraca wartość skrótu dla bieżącego UrlAttributeelementu .

GetPropertiesForNewContext(IConstructionCallMessage)

Wymusza utworzenie kontekstu i obiektu serwera wewnątrz kontekstu w określonym adresie URL.

GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
IsContextOK(Context, IConstructionCallMessage)

Zwraca wartość logiczną wskazującą, czy określona wartość Context spełnia UrlAttributewymagania.

IsDefaultAttribute()

Podczas zastępowania w klasie pochodnej wskazuje, czy wartość tego wystąpienia jest wartością domyślną dla klasy pochodnej.

(Odziedziczone po Attribute)
IsNewContextOK(Context)

Ten interfejs API obsługuje infrastrukturę produktu i nie jest przeznaczony do użycia bezpośrednio z poziomu kodu.

Zwraca wartość logiczną wskazującą, czy właściwość kontekstu jest zgodna z nowym kontekstem.

(Odziedziczone po ContextAttribute)
Match(Object)

Po przesłonięciu w klasie pochodnej zwraca wartość wskazującą, czy to wystąpienie jest równe określonemu obiektowi.

(Odziedziczone po Attribute)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Jawne implementacje interfejsu

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Zestaw nazw jest mapowany na odpowiedni zestaw identyfikatorów wysyłania.

(Odziedziczone po Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Pobiera informacje o typie dla obiektu, który może służyć do pobierania informacji o typie dla interfejsu.

(Odziedziczone po Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Pobiera informację o liczbie typów interfejsów, jakie zawiera obiekt (0 lub 1).

(Odziedziczone po Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Umożliwia dostęp do właściwości i metod udostępnianych przez obiekt.

(Odziedziczone po Attribute)

Dotyczy

Zobacz też