和remoting通信,建立信道设置超时的问题。
xieqi 2010-12-16 10:28:42 网上看到调用remoting设置超时的方法。
TcpChannel liebiao_tcpChannel;
if (liebiao_tcpChannel == null)
{
Hashtable props = new Hashtable();
props["name"] = "tcp_timeout1";
props["timeout"] = 3000;
liebiao_tcpChannel = new TcpChannel(props, null, null);
ChannelServices.RegisterChannel(liebiao_tcpChannel, false);
}
Remoting_function remoteobj = (Remoting_function)Activator.GetObject(typeof(Remoting_function), liebiao_url);
这个设置方法运行3秒就超时,没问题。
但是如果我有2个remoting。我调用2个设置超时不一样就不行了。
TcpChannel liebiao_tcpChannel2;
if (liebiao_tcpChannel2 == null)
{
Hashtable props = new Hashtable();
props["name"] = "tcp_timeout2";
props["timeout"] = 6000;
liebiao_tcpChannel2 = new TcpChannel(props, null, null);
ChannelServices.RegisterChannel(liebiao_tcpChannel2, false);
}
Remoting_function2 remoteobj2 = (Remoting_function2)Activator.GetObject(typeof(Remoting_function2), liebiao_url2);
这样不管掉哪个remoting,超时要么全是3秒,要么全是6秒。重启iis后,先调remoteobj2 的方法,再调remoteobj ,超时全是6秒。重启iis后,反过来先调remoteobj 的方法,超时就全3秒。
下面是查看信道。确实开了2个。
System.Runtime.Remoting.Channels.IChannel[] myIChannelArray = System.Runtime.Remoting.Channels.ChannelServices.RegisteredChannels;
for (int i = 0; i < myIChannelArray.Length; i++)
{
Response.Write("Name of Channel: "+ myIChannelArray[i].ChannelName);
Response.Write("Priority of Channel: "+myIChannelArray[i].ChannelPriority);
}
Name of Channel: tcp_timeout1Priority of Channel: 1
Name of Channel: tcp_timeout2Priority of Channel: 1
怎么才能使2个超时设置各用各的呢?