class Program
{
static void Main(string[] args)
{
BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();
IDictionary props = new Hashtable();
props["port"] = 9999;
TcpChannel channel = new TcpChannel(props, clientProv, serverProv); ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Server), "MyServer", WellKnownObjectMode.Singleton);
var server = (Server)Activator.GetObject(typeof(Server), "tcp://localhost:9999/MyServer");
Console.WriteLine(server.Name);
Console.ReadLine();
}
}class Server:MarshalByRefObject
{
public string Name { get; private set; } public Server()
{
Name = "aaa";
} public Server(string name)
{
Name = name;
}
}用以上代码创建出来的Server名字都叫aaa。有什么办法能够在RegisterWellKnownServiceType的时候传指定的name给Server?假如我要创建多个Server,让他们有不同的名字也比较好识别。虽然他们的url已经不同了,但url并不为Server所知啊。