Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
2 out of 2 rated this helpful - Rate this topic

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)

[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public sealed class UrlAttribute : ContextAttribute
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class UrlAttribute extends ContextAttribute
SerializableAttribute 
ComVisibleAttribute(true) 
public final class UrlAttribute extends ContextAttribute

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;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Activation;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Security.Permissions;

public class Client
{
[SecurityPermission(SecurityAction.Demand)]
    [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.");
    }
}

The following code example shows a server for this client:

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

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

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

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 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft. All rights reserved.