Remoting对象错误:Unable to connect to the remote server

cxx1997 2006-10-27 05:17:19
服务端有两个MBR类,TSystem、TDBSQLControl
TSystem以Singleton方式注册,其提供一个方法GetDBControl()给客户端提供TDBSQLControl类

客户端Activator.GetObject得到TSystem实例后,通过TSystem得到TDBSQLControl实例
现在的问题是这个实例无法访问,即使是.ToString()方法,都会出错


我实验了几种情况:
1:如果以我的开发电脑(XP系统)做服务器,那么一切都正常
2:如果以服务器(2003SERVER)做服务器,如果客户机是内网端口192.168.2.60,也一切都正常
3:如果以服务器(2003SERVER)做服务器,如果客户机是外网端口192.168.117.60,
那么出现错误:由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败
奇怪的是TSystem实例已经正常获得,并能正常操作。


服务器(2003SERVER)做服务器具有两个网址 192.168.2.61 和222.190.196.245

请教各位是什么问题?多谢

服务端代码
namespace nsBusiness
{
public class TSystem:MarshalByRefObject
{
public TSystem()
{
}
public virtual string Login(string aUserName,string aPassword)
{
string LoginID = aUserName + aPassword;
Console.WriteLine("User Login:{0};{1}");
return LoginID;
}
public nsDBControl.TDBSQLControl GetDBControl()
{
return new nsDBControl.TDBSQLControl();
}

}
}
namespace nsDBControl
{
public class TDBSQLControl : MarshalByRefObject
{
public TDBSQLControl()
{
}
public DataSet Query(string aSql, string str)
{
Console.WriteLine("Query" + aSql);
return null;
}
}
}

class Program
{
static void Main(string[] args)
{
nsBusiness.TSystem System = new nsBusiness.TSystem();
RemotingConfiguration.Configure("JSSCServerRemotingConfig.config", false);
PublicTDBSQLControl();
Console.ReadLine();
}
public static void PublicTDBSQLControl()
{
System.Type objType = typeof(nsBusiness.TSystem);
RemotingConfiguration.RegisterWellKnownServiceType(objType, "Mark1", WellKnownObjectMode.Singleton);

}
}

JSSCServerRemotingConfig.config文件内容:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<channels>
<channel port="9019" ref="tcp"/>
<channel port="9089" ref="http"/>
</channels>
</application>
<customErrors mode="Off"/>
</system.runtime.remoting>
</configuration>

客户端代码
nsBusiness.TSystem sys = (nsBusiness.TSystem)Activator.GetObject(typeof(nsBusiness.TSystem),
"http://222.190.196.245:8089/mark2");;
string loginid=sys.Login("aa", "bb");
nsDBControl.TDBSQLControl db = sys.GetDBControl();
db.Query("ccc","cbbb"); --出错,错误:由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败
MessageBox.Show("OK!");

详细错误信息:
Server stack trace:
at System.Net.HttpWebRequest.GetRequestStream()
at System.Runtime.Remoting.Channels.Http.HttpClientTransportSink.ProcessAndSend(IMessage msg, ITransportHeaders headers, Stream inputStream)
at System.Runtime.Remoting.Channels.Http.HttpClientTransportSink.ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream)
at System.Runtime.Remoting.Channels.SoapClientFormatterSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at nsDBControl.TDBSQLControl.Query(String aSql, String str)
at TestConnect.Form1.button3_Click(Object sender, EventArgs e) in D:\DOTNET2005\TestConnect\TestConnect\Form1.cs:line 94


...全文
2762 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
cxx1997 2006-10-30
  • 打赏
  • 举报
回复
现在的问题是:
2003 上装了2个网卡
每个客户端激活对象都会自动分配一个新的URL
这个新的URL不能被正确访问

请问,如何得到这个URL?
zlkingdom 2006-10-30
  • 打赏
  • 举报
回复
如果是这个报错你应该还没有获得服务器端的实例,只是初始化了本地的实例,你用的什么连接信道啊?TCP还是HTTP的?用TCP的会好些
jijl2001 2006-10-30
  • 打赏
  • 举报
回复
试试在防火墙中加入这个程序的例外
cxx1997 2006-10-30
  • 打赏
  • 举报
回复
好!问题解决了!多谢各位!
cxx1997 2006-10-30
  • 打赏
  • 举报
回复
晕死啊,重起2003 ,先启动外网网卡,再启动内网网卡,居然可以了!!!!
股神 2006-10-27
  • 打赏
  • 举报
回复
up
cxx1997 2006-10-27
  • 打赏
  • 举报
回复
aafshzj(上海北京) :是的
aafshzj 2006-10-27
  • 打赏
  • 举报
回复
db.Query("ccc","cbbb")

返回什么?

HandleReturnMessage报错。
cxx1997 2006-10-27
  • 打赏
  • 举报
回复
不好意思,222.190.196.245:8089写错了,是222.190.196.245:9089

这个地址是可以访问的

aafshzj 2006-10-27
  • 打赏
  • 举报
回复
为什么服务端:
<channel port="9019" ref="tcp"/>
<channel port="9089" ref="http"/>

客户端:

222.190.196.245:8089



另外,无论是哪个端口,服务器端(包括服务器、网关、其它防攻击设备)防火墙打开了吗?
你最好和你们的网关谈一下,告诉他:“我要从外网访问内网这台机器的的**端口”。
Knight94 2006-10-27
  • 打赏
  • 举报
回复
直接通过IE访问"http://222.190.196.245:8089/mark2"是否可以呢
Knight94 2006-10-27
  • 打赏
  • 举报
回复
to 3:如果以服务器(2003SERVER)做服务器,如果客户机是外网端口192.168.117.60,
那么出现错误:由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败
奇怪的是TSystem实例已经正常获得,并能正常操作。

TSystem实例已经正常获得了?

这就很怪了。
aafshzj 2006-10-27
  • 打赏
  • 举报
回复
网络设备设置问题。

110,578

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧