首页 新闻 会员 周边 捐助

remoting 经常报找不到服务

0
悬赏园豆:50 [已关闭问题] 关闭于 2008-10-27 16:26

问题描述如下:

一个服务端,装有MQ,希望能够把MQ的消息广播出来,客户端接收。。。。

 

对象定义如下:

 

服务端:

   public class MQService : MarshalByRefObject
    {
        public static MQService Default = new MQService();

        private MQServiceDelegate _MQMessageRecived;
        public event MQServiceDelegate MQMessageRecived
        {
            add
            {
                MQService.Default._MQMessageRecived += value;
            }
            remove
            {
                MQService.Default._MQMessageRecived -= value;
            }
        }

        public void OnMQMessageRecived(MQServiceEventArgs msg)
        {
            if (_MQMessageRecived != null)
            {
               
                    _MQMessageRecived(msg);
              }         
        }
    }

客户端:

    public class MQClient : MarshalByRefObject
    {
        public MQClient(Predicate<MQServiceEventArgs> predicate)
        {
            Predicate = predicate;
        }

        private Predicate<MQServiceEventArgs> Predicate;

        public event MQServiceDelegate MQMessageRecived;


        public void OnMQMessageRecived(MQServiceEventArgs MQServiceEventArgs)
        {
            if (Predicate(MQServiceEventArgs))
            {
                MQMessageRecived(MQServiceEventArgs);
            }
        }
    }

上面两个都编译到同一个dll中,服务端和客户端都添加引用。。。

 

服务端注册信道等:

   IDictionary properties = new Hashtable();
                RunLogs = string.Format("开始读取服务名称!");
                this.serverName = CFunction.GetConfigFromXML("ServerConfig/Remoting/ClassName");
                RunLogs = string.Format("读取远程服务名称成功!服务名为:{0}", serverName);
                RunLogs = string.Format("开始读取远程服务端口配置!");
                this.serverPort = CFunction.GetConfigFromXML("ServerConfig/Remoting/Port");
                RunLogs = string.Format("读取远程端口配置成功!服务端口为:{0}", serverPort);

                properties["name"] = serverName;
                properties["port"] = serverPort;

                BinaryClientFormatterSinkProvider cbin = new BinaryClientFormatterSinkProvider();
                BinaryServerFormatterSinkProvider sbin = new BinaryServerFormatterSinkProvider();
                sbin.TypeFilterLevel = TypeFilterLevel.Full;

                RunLogs = string.Format("开始创建远程服务通道对象!");
                this.mcc_channel = new TcpChannel(properties, cbin, sbin);
                RunLogs = string.Format("创建远程服务通道对象成功!");
                RunLogs = string.Format("开始注册远程服务通道!");
                ChannelServices.RegisterChannel(this.mcc_channel, false);
                RunLogs = string.Format("注册远程服务通道成功!");
                this.serverRemoteName = CFunction.GetConfigFromXML("ServerConfig/Remoting/ServerRemoteName"); ;
                RunLogs = string.Format("开始广播远程服务通道!广播对象类型:{0}", this.serverRemoteName);
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(MQService), serverRemoteName, WellKnownObjectMode.Singleton);
                RunLogs = string.Format("广播远程服务通道成功!");
                RunLogs = string.Format("启动服务成功了!");

 

客户端注册信道等:

  IDictionary properties = new Hashtable();
            properties["name"] = "BoCo.Hubei.Common.Test.MQClient";
            properties["port"] = "8002";


            TcpChannel channel = new TcpChannel(8002);//(properties,null,new BinaryServerFormatterSinkProvider());
            ChannelServices.RegisterChannel(channel, false);
            RemotingConfiguration.RegisterWellKnownClientType(typeof(MQService), "tcp://localhost:8001/BoCo.Hubei.Common.Server.MQServer.IMQservice");

 

如上的注册,正确通过。。

 

客户端接受广播消息:

  MQService Default = (MQService)Activator.GetObject(MQService.Default.GetType(), "tcp://localhost:8001/BoCo.Hubei.Common.Server.MQServer.IMQservice");
           
            MQClient test = new MQClient(a => !string.IsNullOrEmpty(a.MQMessage));

            test.MQMessageRecived += new MQServiceDelegate(test_MQMessageRecived);

            Default.MQMessageRecived += test.OnMQMessageRecived;

 

程序运行结果描述:

服务端消息能够实现广播,并且客户端也能够收到消息,但是,程序运行一会,非常短的时间后,

服务端的此处将报一个错误:

_MQMessageRecived(msg);

”错误为找不到指定的服务 “

 

现寻求解决办法:

1:是否是注册tcpchannel的时候,需要制定timeout时间?(但是,好像我把时间设置为-1或者0后,还是会出现如上的错误)

2:是否可以设置一个心跳线程,用于判断TcpChannel是否链接正常??

 

跪求各位老大给个解决办法。。。。。。。。。。。。。。。。。

颜昌钢的主页 颜昌钢 | 初学一级 | 园豆:150
提问于:2008-10-26 18:28
< >
分享
所有回答(2)
0
RicoRui | 园豆:3663 (老鸟四级) | 2008-10-27 10:47
0

有解决嘛,我也遇到这个问题,remoting 请求找不到服务,处理了一天了,没有思路,如果有解决麻烦回复下,谢谢

aXinNo1 | 园豆:570 (小虾三级) | 2021-06-29 17:58
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册