Remoting 找不到请求的服务

aimyray 2011-05-17 05:05:44
c#高级编程书上的例子:
服务器端:
HelloServer:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using RemoteHello;

namespace HelloWerver
{
class Program
{
static void Main(string[] args)
{
TcpServerChannel channel = new TcpServerChannel(8086);


HelloServer.ShowChannelProperties(channel);
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Hello), "Hi", WellKnownObjectMode.SingleCall);//把知名的远程对象类型注册为RemotingServices

System.Console.WriteLine("press return to exit");
System.Console.ReadLine();
//channel.ChannelData
}
}
}

RemoteHello.dll:
using System;
using System.Collections.Generic;
using System.Text;

namespace RemoteHello
{
public class Hello:System.MarshalByRefObject
{
public Hello()
{
Console.WriteLine("Constructor called");
}

~Hello()
{
Console.WriteLine("Destructor called");
}

public string Greeting(string name)
{
Console.WriteLine("Greeting called");
return "Hello," + name;
}
}
}

客户端:HelloClient2
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Activation;
using RemoteHello;

namespace HelloClient2
{
class Program
{
static void Main(string[] args)
{
//object[] attrs ={ new UrlAttribute("tcp://localhost:8086/HelloServer") };
//ObjectHandle handle = Activator.CreateInstance("RemoteHello", "RemoteHello.Hello", attrs);

//if (handle == null)
//{
// Console.WriteLine("could not locate server");
// return;
//}
RemotingConfiguration.RegisterActivatedClientType(typeof(Hello), "tcp://localhost:8086/HelloServer");
Hello obj = new Hello();//(Hello)handle.Unwrap();
Console.WriteLine(obj.Greeting("Christian"));
Console.ReadLine();
}
}
}

客户端运行到 RemotingConfiguration.RegisterActivatedClientType(typeof(Hello), "tcp://localhost:8086/HelloServer");
出现异常提示:找不到指定服务。
...全文
461 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
aimyray 2011-05-17
  • 打赏
  • 举报
回复
服务器端用 RemotingConfiguration.RegisterActivatedServiceType(typeof(Hello));解决
aimyray 2011-05-17
  • 打赏
  • 举报
回复
服务器端已经运行了,
RemotingConfiguration.RegisterActivatedClientType(typeof(Hello), "tcp://localhost:8086/HelloServer")换成RemotingConfiguration.RegisterWellKnownClientType(typeof(Hello), "tcp://localhost:8086/Hi");就可以。换成RemotingConfiguration.RegisterActivatedClientType(typeof(Hello), "tcp://localhost:8086/Hi")还是同样的错误。
灵雨飘零 2011-05-17
  • 打赏
  • 举报
回复
先运行服务端
yao2004jessica 2011-05-17
  • 打赏
  • 举报
回复
服务端先运行
lovebibi168 2011-05-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 am 的回复:]
应该先运行服务端,子服务端运行后,在运行客户端
[/Quote]
UP
aimyray 2011-05-17
  • 打赏
  • 举报
回复
服务器运行了
am 2011-05-17
  • 打赏
  • 举报
回复
应该先运行服务端,子服务端运行后,在运行客户端

110,533

社区成员

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

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

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