This documentation is archived and is not being maintained.

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.

Namespace:  System.Runtime.Remoting.Activation
Assembly:  mscorlib (in mscorlib.dll)

'Declaration
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class UrlAttribute _
	Inherits ContextAttribute
'Usage
Dim instance As UrlAttribute

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:

No code example is currently available or this language may not be supported.
#using <mscorlib.dll>
#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(S"Client starting.");

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

	// Create UrlAttribute.
	UrlAttribute* attribute = new UrlAttribute(S"tcp://localhost:1234/RemoteApp");
	Console::WriteLine(S"UrlAttribute value: {0}", attribute->UrlValue);
	Object* activationAttributes[] = { attribute };

	// Use UrlAttribute to register for client activated remote object.
	RemotingConfiguration::RegisterActivatedClientType(__typeof(RemoteObject), 
		S"tcp://localhost:1234/RemoteApp");

	// Activate remote object.
	Console::WriteLine(S"Activating remote object.");
	RemoteObject* obj = dynamic_cast<RemoteObject*>
		(Activator::CreateInstance(__typeof(RemoteObject), 0, activationAttributes));

	// Invoke a method on it.
	Console::WriteLine(S"Invoking Hello() on remote object.");
	obj->Hello();

	// Inform user of termination.
	Console::WriteLine(S"Terminating client.");
}

The following code example shows a server for this client:

No code example is currently available or this language may not be supported.
#using <mscorlib.dll>
#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(S"Server starting.");

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

	// Set application name.
	RemotingConfiguration::ApplicationName = S"RemoteApp";

	// Register object for client activated remoting.
	RemotingConfiguration::RegisterActivatedServiceType(__typeof(RemoteObject));

	// Wait until termination.
	Console::WriteLine(S"Press enter to end.");
	Console::ReadLine();
	Console::WriteLine(S"Terminating server.");
}

The following code example shows the remote object that is used by the client and the server:

No code example is currently available or this language may not be supported.
#using <mscorlib.dll>
using namespace System;
using namespace System::Security;
using namespace System::Security::Permissions;

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

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

System.Object
  System.Attribute
    System.Runtime.Remoting.Contexts.ContextAttribute
      System.Runtime.Remoting.Activation.UrlAttribute

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Show: