UrlAttribute Class
Defines an attribute that can be used at the call site to specify the URL where the activation will happen. This class cannot be inherited.
System::Attribute
System.Runtime.Remoting.Contexts::ContextAttribute
System.Runtime.Remoting.Activation::UrlAttribute
Assembly: mscorlib (in mscorlib.dll)
The UrlAttribute type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | Equals | Checks whether the specified object refers to the same URL as the current instance. (Overrides ContextAttribute::Equals(Object).) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | Freeze | Infrastructure. Called when the context is frozen. (Inherited from ContextAttribute.) |
![]() | GetHashCode | Returns the hash value for the current UrlAttribute. (Overrides ContextAttribute::GetHashCode().) |
![]() | GetPropertiesForNewContext | Forces the creation of the context and the server object inside the context at the specified URL. (Overrides ContextAttribute::GetPropertiesForNewContext(IConstructionCallMessage).) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | IsContextOK | Returns a Boolean value that indicates whether the specified Context meets UrlAttribute's requirements. (Overrides ContextAttribute::IsContextOK(Context, IConstructionCallMessage).) |
![]() | IsDefaultAttribute | When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Inherited from Attribute.) |
![]() | IsNewContextOK | Infrastructure. Returns a Boolean value indicating whether the context property is compatible with the new context. (Inherited from ContextAttribute.) |
![]() | Match | When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
| Name | Description | |
|---|---|---|
![]() | AttributeName | Infrastructure. Indicates the name of the context attribute. (Inherited from ContextAttribute.) |
| Name | Description | |
|---|---|---|
![]() ![]() | _Attribute::GetIDsOfNames | Maps a set of names to a corresponding set of dispatch identifiers. (Inherited from Attribute.) |
![]() ![]() | _Attribute::GetTypeInfo | Retrieves the type information for an object, which can be used to get the type information for an interface. (Inherited from Attribute.) |
![]() ![]() | _Attribute::GetTypeInfoCount | Retrieves the number of type information interfaces that an object provides (either 0 or 1). (Inherited from Attribute.) |
![]() ![]() | _Attribute::Invoke | Provides access to properties and methods exposed by an object. (Inherited from Attribute.) |
The UrlAttribute is passed in the activation attributes array as a parameter to Activator::CreateInstance when creating activated objects with the CreateInstance method.
For more information about using attributes, see Extending Metadata Using Attributes.
The following code example illustrates the use of the UrlAttribute in setting up client-activated remoting. The example contains three parts: a client, a server, and a remote object that is used by the client and server.
The following code example shows a client:
#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." ); }
The following code example shows a server for this client:
#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." ); }
The following code example shows the remote object that is used by the client and the 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()." ); } };
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
