老是提示“找不到请求的服务”--关于Remoting的问题!

ipqn 2007-03-18 04:14:08
今天在Vs2005测试Remoting,我是如下些的!
服务器:
using .....(省略掉)

namespace RS
{
public class RemotingService
{
public static void Main()
{
TcpServerChannel channel = new TcpServerChannel( 8086 );
ChannelServices.RegisterChannel( channel,true );
WellKnownServiceTypeEntry swte = new WellKnownServiceTypeEntry( typeof( SC.ServerClass ), "GNT", WellKnownObjectMode.SingleCall );
Console.WriteLine( "Server is runing..." );
Console.ReadLine();
}
}
}

namespace SC
{
public class ServerClass : MarshalByRefObject
{

public string GetNowTime()
{
return DateTime.Now.ToString();
}
}
}

客户端:
using .....(省略掉)

namespace RC
{
public class RemotingClient
{
public static void Main()
{
ChannelServices.RegisterChannel( new TcpClientChannel(),true );
ServerClass sc = (ServerClass)Activator.GetObject( typeof( ServerClass ), "tcp://localhost:8086/Hi" );
Console.WriteLine( sc.GetNowTime() );
Console.ReadLine();
}
}
}

当客户端运行到Console.WriteLine( sc.GetNowTime() );的时候老是提示“找不到请求的服务”,我记得以前在2003里边这么写就没问题的嘛!

请问:这是什么原因造成的?如何解决?
...全文
1539 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
aidajia 2009-10-05
  • 打赏
  • 举报
回复
高手快来解答呀!等..........
aidajia 2009-10-05
  • 打赏
  • 举报
回复
服务
//注册信道
TcpServerChannel channel = new TcpServerChannel(9090);
ChannelServices.RegisterChannel(channel);
//将remoteobject.myobject注册为已知类型
RemotingConfiguration.RegisterWellKnownServiceType(typeof(remoteobject.myobject), "add", WellKnownObjectMode.SingleCall);

Console.WriteLine("Server is runing... ");
Console.ReadLine();
客户
myobject app = (myobject)Activator.GetObject(typeof(myobject), "tcp://localhost:9090/add");
if (app != null)
{
int a = app.add(1, 2);
Console.WriteLine(a.ToString());
}
Console.ReadLine();

public class myobject : MarshalByRefObject
{
public int add(int a, int b)
{
return a + b;
}
}
有什么不同吗??
我的可以呀???
  • 打赏
  • 举报
回复
为什么不能把服务器端的日期显示出来呢,我运行了一下,运行到取日期那儿就在那儿锁死了,怎么回事呢!!!
wangcan05528845048 2008-11-09
  • 打赏
  • 举报
回复
服务器端没有注册是一个严重错误,注册服务器端后你再试验把 "ChannelServices.RegisterChannel( channel,true )"里的"true“去掉
IP2005 2007-03-18
  • 打赏
  • 举报
回复
messm() 是在误人子弟!

你服务端都没注册!
在WellKnownServiceTypeEntry swte = new WellKnownServiceTypeEntry( typeof( SC.ServerClass ), "GNT", WellKnownObjectMode.SingleCall );后,添加上RemotingConfiguration.RegisterWellKnownServiceType( swte );
ipqn 2007-03-18
  • 打赏
  • 举报
回复
UP again
ipqn 2007-03-18
  • 打赏
  • 举报
回复
UP
ipqn 2007-03-18
  • 打赏
  • 举报
回复
汗!
弄到2003里也没法运行!
docb 2007-03-18
  • 打赏
  • 举报
回复
TCP 的没这么简单
如果是http协议的就
HttpChannel channel = new HttpChannel( 8086 ); 可以了
但是Tcp的还要一堆初始化的

url = @"tcp://LocalHost:8086/GNT";
BinaryClientFormatterSinkProvider clientProvider =
new BinaryClientFormatterSinkProvider();

BinaryServerFormatterSinkProvider serverProvider =
new BinaryServerFormatterSinkProvider();

serverProvider.TypeFilterLevel =
System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

IDictionary props = new Hashtable();
props["port"] = 0;
props["name"] = System.Guid.NewGuid().ToString();
props["typeFilterLevel"] = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

TcpChannel chan =
new TcpChannel(props, clientProvider, serverProvider);
ipqn 2007-03-18
  • 打赏
  • 举报
回复
没问题啊!
heartdevil 2007-03-18
  • 打赏
  • 举报
回复
地址没有设置对.系统找不到指定的地址上面的服务.你看看相对路径是不是对的.
ipqn 2007-03-18
  • 打赏
  • 举报
回复
写错了,改一下
客户端里的的ServerClass sc = (ServerClass)Activator.GetObject( typeof( ServerClass ), "tcp://localhost:8086/Hi" );
“Hi”是“GNT”

110,545

社区成员

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

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

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