none
remoting动态加载dll,客户端提示“找不到请求的服务” RRS feed

  • 问题

  • 我在AppDomainLoader创建AppDomain,在RemoteLoader使用assembly,然后在windows服务里启动,现在问题是服务端启动没有错误,但在客户端iTest = (ITest)(Activator.GetObject(typeof(ITest), "tcp://localhost:8989/Test")); Response.Write(iTest.Hello());运行到输出时提示“找不到请求的服务”,Response.Write(iRemote.GetType().ToString());得到的是System.MarshalByRefObject.

    我将windows服务移植到控制台应用程序上,逐步运行下来,在Assembly _assembly = Assembly.LoadFrom(url);
                Type[] t = _assembly.GetExportedTypes();可以得到类的名称。

    网上找了好久,好像是说客户端得不到远程的。个人怀疑是不是服务端的assembly没有work,不过不知道该怎样修改。下面贴下服务端代码:

     

     BinaryClientFormatterSinkProvider cbin = new BinaryClientFormatterSinkProvider();
                        BinaryServerFormatterSinkProvider sbin = new BinaryServerFormatterSinkProvider();
                        sbin.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

                        Hashtable properties = new Hashtable();
                        properties["port"] = dt.Rows[i]["Port"].ToString();

                        TcpChannel channel = new TcpChannel(properties, cbin, sbin);
                        ChannelServices.RegisterChannel(channel, false);

                        DataTable dTable = _remoteManager.RemoteList();
                        for (int j = 0; j < dTable.Rows.Count; j++)
                        {
                            //得到dll文件保存路径
                            string url = filename + dTable.Rows[j]["Key"].ToString();
                            AppDomainLoader appDomain = new AppDomainLoader();
                            appDomain.CreateAppDomain(url);
                        }

     

     

     

    public void CreateAppDomain(string url)
            {
                AppDomainSetup setup = new AppDomainSetup();
                setup.ShadowCopyFiles = "true";
                setup.DisallowBindingRedirects = false;
                setup.DisallowCodeDownload = true;
                setup.ConfigurationFile =
                    AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;


                //创建程序域
                string aname = Assembly.GetExecutingAssembly().GetName().FullName;
                AppDomain appDomain = AppDomain.CreateDomain(url, null, setup);

               
                ht.Add(url, appDomain);
                //在创建的程序域中读取
                RemoteLoader test = (RemoteLoader)appDomain.CreateInstanceAndUnwrap(aname, "Explorer.Framework.Service.RemoteLoader");
                test.StartAssembly(url);
            }

     

     

     public void StartAssembly(string url)
            {
                Assembly _assembly = Assembly.LoadFrom(url);
                Type[] t = _assembly.GetExportedTypes();
                foreach (Type type in t)
                {
                    RemotingConfiguration.RegisterWellKnownServiceType(type, type.Name, WellKnownObjectMode.SingleCall);
                }

            }

    • 已编辑 若_水 2010年11月5日 7:40 补充
    2010年11月5日 7:36