UrlAttribute Třída

Definice

Definuje atribut, který lze použít na volajícím webu k určení adresy URL, kde se aktivace stane. Tuto třídu nelze dědit.

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
Dědičnost
Atributy

Příklady

Následující příklad kódu znázorňuje použití UrlAttribute při nastavování vzdálené komunikace aktivované klientem. Příklad obsahuje tři části: klient, server a vzdálený objekt, který používá klient a server.

Následující příklad kódu ukazuje 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.");
    }
}

Následující příklad kódu ukazuje server pro tohoto 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.");
    }
}

Následující příklad kódu ukazuje vzdálený objekt, který používá klient a server:

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().");
    }
}

Poznámky

Pole UrlAttribute atributů aktivace se předává jako parametr při Activator.CreateInstance vytváření aktivovaných objektů pomocí CreateInstance metody.

Další informace o používání atributů najdete v tématu Atributy.

Konstruktory

UrlAttribute(String)

Vytvoří novou instanci třídy UrlAttribute.

Pole

AttributeName

Toto rozhraní API podporuje produktovou infrastrukturu a není určené k použití přímo z uživatelského kódu.

Určuje název atributu kontextu.

(Zděděno od ContextAttribute)

Vlastnosti

Name

Toto rozhraní API podporuje produktovou infrastrukturu a není určené k použití přímo z uživatelského kódu.

Získá název kontextového atributu.

(Zděděno od ContextAttribute)
TypeId

Při implementaci v odvozené třídě získá jedinečný identifikátor pro tento Attribute.

(Zděděno od Attribute)
UrlValue

Získá hodnotu ADRESY URL .UrlAttribute

Metody

Equals(Object)

Zkontroluje, jestli zadaný objekt odkazuje na stejnou adresu URL jako aktuální instance.

Freeze(Context)

Toto rozhraní API podporuje produktovou infrastrukturu a není určené k použití přímo z uživatelského kódu.

Volá se při zmrazení kontextu.

(Zděděno od ContextAttribute)
GetHashCode()

Vrátí hodnotu hash pro aktuální UrlAttributehodnotu .

GetPropertiesForNewContext(IConstructionCallMessage)

Vynutí vytvoření kontextu a objektu serveru uvnitř kontextu na zadané adrese URL.

GetType()

Type Získá aktuální instanci.

(Zděděno od Object)
IsContextOK(Context, IConstructionCallMessage)

Vrátí logickou hodnotu, která označuje, jestli zadaný Context parametr splňuje UrlAttributepožadavky.

IsDefaultAttribute()

Při přepsání v odvozené třídě určuje, zda hodnota této instance je výchozí hodnotou odvozené třídy.

(Zděděno od Attribute)
IsNewContextOK(Context)

Toto rozhraní API podporuje produktovou infrastrukturu a není určené k použití přímo z uživatelského kódu.

Vrací logickou hodnotu, která označuje, zda je vlastnost Context kompatibilní s novým kontextem.

(Zděděno od ContextAttribute)
Match(Object)

Při přepsání v odvozené třídě vrátí hodnotu, která označuje, zda se tato instance rovná zadanému objektu.

(Zděděno od Attribute)
MemberwiseClone()

Vytvoří použádnou kopii aktuálního souboru Object.

(Zděděno od Object)
ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)

Explicitní implementace rozhraní

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

Mapuje sadu názvů na odpovídající sadu identifikátorů pro rozesílání.

(Zděděno od Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Načte informace o typu objektu, který lze použít k získání informací o typu rozhraní.

(Zděděno od Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Získá počet rozhraní typu informací, které objekt poskytuje (0 nebo 1).

(Zděděno od Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Poskytuje přístup k vlastnostem a metodám vystaveným objektem.

(Zděděno od Attribute)

Platí pro

Viz také