请问remoting中代理类能否在构造函数中加参数,又如何调用呢,谢谢
解决方案 »
- c# 怎么控制2个线程不能同时运行?
- Math.Asin(25/35)为什么是0?
- tcpSocket通信的问题,急,急!
- Image.FromFile 方法怎么给图片加背景颜色
- C#高级编程(第6版)与C#高级编程(第4版)原有部分是不是不一样了?还是只是添加了了些新章节,原有部分没变?
- 64位操作系统上如何连接ACCESS数据库??
- 打开窗口的问题
- 要实现类似阿里巴巴里的“贸易通”的功能,如何实现?
- windows身份验证问题,请高手帮忙,多谢!!!(解决后开新贴再送100分)
- EntityFramework不同类型对比
- C# 发送邮件,总是发不出去,IIS 自带的smtp是不是有问题? 还是我有代码有问题?
- 数据表的更新
{public ServerObject(string dint)
{
//其它功能
}
public Person GetPersonInfo(string name,string sex,int age)
{
Person person = new Person();
person.Name = name;
person.Sex = sex;
person.Age = age;
return person;
}
}
这样能行吗如何调用呢,谢谢高手给指点
using System;public class HelloServiceClass : MarshalByRefObject
{ static int n_instance; public HelloServiceClass(string teststr)
{
Console.WriteLine(teststr);
}
public HelloServiceClass()
{
n_instance++;
Console.WriteLine(this.GetType().Name + " has been created. Instance # = {0}", n_instance);
}
~HelloServiceClass()
{
Console.WriteLine("Destroyed instance {0} of HelloServiceClass.", n_instance);
n_instance --;
}
public String HelloMethod(String name)
{ // Reports that the method was called.
Console.WriteLine();
Console.WriteLine("Called HelloMethod on instance {0} with the '{1}' parameter.",
n_instance, name); // Calculates and returns the result to the client.
return "Hi there " + name + ".";
}
}服务器端ServerClass.csusing System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Collections;
public class ServerClass
{ public static void Main()
{
try
{ TcpChannel [] TcpChannels = new TcpChannel[2]; for( int i =0;i<2;i++)
{
IDictionary props = new Hashtable();
props["name"] = "tcpChannel"+i.ToString();
props["port"] = 5000+i;
TcpChannel channel = new TcpChannel(
props,
null,
new BinaryServerFormatterSinkProvider()
);
ChannelServices.RegisterChannel(channel); RemotingConfiguration.RegisterActivatedServiceType(typeof(HelloServiceClass)); props.Clear();
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message+ex.StackTrace);
} Console.WriteLine("Press enter to stop this process.");
Console.ReadLine();
}
}客户端调用:
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;public class ClientClass
{ public static void Main()
{
try
{
for( int i =0;i<2;i++)
{ ChannelServices.RegisterChannel(new TcpChannel()); RemotingConfiguration.RegisterActivatedClientType(typeof(HelloServiceClass),
//"tcp://localhost:8082");
"tcp://localhost:"+(5000+i).ToString()); HelloServiceClass service = new HelloServiceClass("testaaa"+(5000+i).ToString()); if(service == null)
{
Console.WriteLine("Could not locate server.");
return;
} // Calls the remote method.
Console.WriteLine();
Console.WriteLine("Calling remote object"+i.ToString());
Console.WriteLine(service.HelloMethod("Caveman"));
Console.WriteLine(service.HelloMethod("Spaceman"));
Console.WriteLine(service.HelloMethod("Client Man"));
Console.WriteLine("Finished remote object call");
//Console.WriteLine();
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message+ex.StackTrace);
}
}
}
目标:我想使用多通道的客户端激活模式,能实在代理类构造传参,但在服务器端运行时出现以下错误,本人感到注册的事,但报错是字典的事,所以不理解肯请高手指点或大伙帮找错,谢谢!
其中服务器端运行出错如下:ex.Message
已添加项。字典中的键: “HelloServiceClass, helloserviceclass” 所添加的键: “HelloServiceClass, helloserviceclass