本文整理汇总了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.");
}
}
示例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.");
}
}
示例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().");
}
}