积极答复者
Remoting 小问题。

问题
-
我现在要在服务器断监听多个端口
string[] str = 一个数组,包含如 "1542,1592,4584,4512,6545,5412" .Split(',');;
foreach (string iPort in str)
{
if (iPort.Trim() != "")
{
try
{
TcpServerChannel tcpChannel = new TcpServerChannel("tcpChannel" + iPort, int.Parse(iPort));
RemotingConfiguration.RegisterWellKnownServiceType(typeof(CSAchieve.User), "Service" + iPort, WellKnownObjectMode.SingleCall);
ChannelServices.RegisterChannel(tcpChannel, false);
txtResult.Text += "端口:" + iPort + " 监听成功\r\n";
}
catch (Exception ex)
{
txtResult.Text += "端口:" + iPort + "监听失败,错误:" + ex.Message + "\r\n";
}
}
}
原来是使用app.config配置 使用单端口的
<system.runtime.remoting>
<application name="CSKLSCCC">
<service>
<wellknown mode="SingleCall" type="CSKL.CSAchieve.User, CSKL.CSAchieve" objectUri="Service" />
</service>
<channels>
<channel ref="tcp" port="4000">
<serverProviders>
<formatter ref="soap" typeFilterLevel="Full"/>
<formatter ref="binary" typeFilterLevel="Full"/>
</serverProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
现在该用上面的代码循环监听多个端口后,客户端请求原来的函数,提示找不到服务, 改回原来的单IP使用app.config配置来初始化
RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, false);
这样是正常的,看了半天没找到原因,请教各位大虾来了!- 已移动 Sheng Jiang 蒋晟Moderator 2009年8月17日 4:12 .Net通讯类库问题 (发件人:Visual C#)
答案
-
你监听这么多端口做什么?用socket一个端口就可以搞定。IIS就是这么处理http请求的。
Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
Visual C++ MVP- 已标记为答案 Riquel_DongModerator 2009年8月21日 8:49
-
您好,做如下修改,请参考:
1、服务器端监听多个端口,而服务注册一个即可。把RemotingConfiguration.RegisterWellKnownServiceType拿出来。
foreach (string iPort in str)
{
if (iPort.Trim() != "")
{
try
{
TcpServerChannel tcpChannel = new TcpServerChannel("tcpChannel" + iPort, int.Parse(iPort));
ChannelServices.RegisterChannel(tcpChannel, false);
txtResult.Text += "端口:" + iPort + " 监听成功\r\n";
}
catch (Exception ex)
{
txtResult.Text += "端口:" + iPort + "监听失败,错误:" + ex.Message + "\r\n";
}
}
}
RemotingConfiguration.RegisterWellKnownServiceType(typeof(CSAchieve.User), "Service" , WellKnownObjectMode.SingleCall);
2、客户端用不同端口的url来访问即可。- 已标记为答案 Riquel_DongModerator 2009年8月21日 8:48
全部回复
-
你好你这里 RemotingConfiguration.RegisterWellKnownServiceType(typeof(CSAchieve.User), "Service" + iPort, WellKnownObjectMode.SingleCall);
采用了对象 URI 是"Service”+iPort 而在你的服务器上的配置
<service>
<wellknown mode="SingleCall" type="CSKL.CSAchieve.User, CSKL.CSAchieve" objectUri="Service" />
</service>
却只有Service 因而会出错
Wenn ich dich hab’,gibt es nichts, was unerträglich ist.坚持不懈!http://hi.baidu.com/1987raymond- 已编辑 Raymond TangModerator 2009年8月17日 4:46
-
晕,那如果我要同时监听几十个端口那不是要玩死人了。。。而且端口很可能是动态配置的,监听那么多端口是很有可能的。项目需求!
我个人以为 使用 RemotingConfiguration.RegisterWellKnownServiceType(typeof(CSAchieve.User), "Service" + iPort, WellKnownObjectMode.SingleCall);
就能代替了 <service>
<wellknown mode="SingleCall" type="CSKL.CSAchieve.User, CSKL.CSAchieve" objectUri="Service" />
</service>
所以那样写。。。汗!有没有能用代码的解决方法,配置文件这样写,不大现实! -
而且我在监听多端口的时候,app.config 内的 是直接删除了的。他也没报错啊!
<serverProviders>
<formatter ref="soap" typeFilterLevel="Full"/>
<formatter ref="binary" typeFilterLevel="Full"/>
</serverProviders>
除了 这个,我在代码内没找到方法指定。我猜想会不会是这个原因!而且 如果使用app.config 来配置
RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, false);
这样去注册的话,很麻烦的! -
你监听这么多端口做什么?用socket一个端口就可以搞定。IIS就是这么处理http请求的。
Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
Visual C++ MVP- 已标记为答案 Riquel_DongModerator 2009年8月21日 8:49
-
您好,做如下修改,请参考:
1、服务器端监听多个端口,而服务注册一个即可。把RemotingConfiguration.RegisterWellKnownServiceType拿出来。
foreach (string iPort in str)
{
if (iPort.Trim() != "")
{
try
{
TcpServerChannel tcpChannel = new TcpServerChannel("tcpChannel" + iPort, int.Parse(iPort));
ChannelServices.RegisterChannel(tcpChannel, false);
txtResult.Text += "端口:" + iPort + " 监听成功\r\n";
}
catch (Exception ex)
{
txtResult.Text += "端口:" + iPort + "监听失败,错误:" + ex.Message + "\r\n";
}
}
}
RemotingConfiguration.RegisterWellKnownServiceType(typeof(CSAchieve.User), "Service" , WellKnownObjectMode.SingleCall);
2、客户端用不同端口的url来访问即可。- 已标记为答案 Riquel_DongModerator 2009年8月21日 8:48