读书人

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

发布时间: 2012-01-14 20:02:35 作者: rapoo

老是提示“找不到请求的服务”--关于Remoting的问题!
今天在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里边这么写就没问题的嘛!

请问:这是什么原因造成的?如何解决?

[解决办法]
messm() 是在误人子弟!

你服务端都没注册!
在WellKnownServiceTypeEntry swte = new WellKnownServiceTypeEntry( typeof( SC.ServerClass ), "GNT ", WellKnownObjectMode.SingleCall );后,添加上RemotingConfiguration.RegisterWellKnownServiceType( swte );

读书人网 >C#

热点推荐