当前位置: 首页>>代码示例>>C#>>正文


C# UrlAttribute类代码示例

本文整理汇总了C#中System.Runtime.Remoting.Activation.UrlAttribute的典型用法代码示例。如果您正苦于以下问题:C# UrlAttribute类的具体用法?C# UrlAttribute怎么用?C# UrlAttribute使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


UrlAttribute类属于System.Runtime.Remoting.Activation命名空间,在下文中一共展示了UrlAttribute类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

//引入命名空间
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.");
    }
}
开发者ID:.NET开发者,项目名称:System.Runtime.Remoting.Activation,代码行数:44,代码来源:UrlAttribute

示例2: Main

//引入命名空间
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.");
    }
}
开发者ID:.NET开发者,项目名称:System.Runtime.Remoting.Activation,代码行数:30,代码来源:UrlAttribute

示例3: RemoteObject

//引入命名空间
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().");
    }
}
开发者ID:.NET开发者,项目名称:System.Runtime.Remoting.Activation,代码行数:17,代码来源:UrlAttribute


注:本文中的System.Runtime.Remoting.Activation.UrlAttribute类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。