当前位置:编程学习 > C#/ASP.NET >>

Remoting 传递自定义对象列表问题 急!!!!!!

我想用remoting 传递 hashtable 或 arraylist 给客户端。
先是运行服务器端 再是由客户端调用服务器端远程对象的 set方法向服务器端的对象列表赋值
然后是 由web的客户端 调用get方法取回对象列表。

大致就是这个流程。
在获得对象列表时会报错

“此远程处理代理没有信道接收,这意味着服务器没有正在侦听的已注册服务器信道,或者此应用程序没有用来与服务器对话的适当客户端信道。” 

不知哪位大侠能给个解释, 感激不尽。。。。。


我服务器端远程对象的代码大致为

 public class DataLoader : System.MarshalByRefObject, IGpsLoad
    {

        public Hashtable loadCurrList()
        {
            Console.WriteLine("currlist called");

            return envs.gpscurrlist;
        }

        public Boolean setCurrList(Hashtable infos) {

            if (gpsinfos.Count < 1) return false;
            
            lock (envs.currlist.SyncRoot)
            {
                try
                {
                    foreach (DictionaryEntry de in gpsinfos)
                    {
                        if (envs.currlist.Contains(de.Key))
                        {
                            envs.currlist[de.Key] = de.Value;
                            Console.WriteLine(de.Key.ToString() + ". 数据更新");
                        }
                        else
                        {
                            envs.currlist.Add(de.Key, de.Value);
                            Console.WriteLine(de.Key.ToString() + ". 数据添加");
                        }
                    }
                }
                catch (Exception ex) {
                    Console.WriteLine(ex.Message);
                    return false;
                }
            }
            return true;
        }
    }

namespace Leeing.Web
{
    public class Entity : MarshalByRefObject
    {
        public String testA = "bbb";
        public String testB = "bbb";
    }
}

服务器代码为

namespace Leeing.Webgps
{
    class program
    {
        static void Main(string[] args)
        {
            RemotingConfiguration.Configure(AppDomain.CurrentDomain.BaseDirectory + "\\GPSRemoteServer.config", false);

            Console.ReadLine();
        }
    }
}

配置文件为

<configuration>
  <system.runtime.remoting>
    <customErrors mode="Off"/>
    <application name="RemoteServer">
      <service>
        <wellknown mode="SingleCall" type="Leeing.Web.DataLoader, WebHolder" objectUri="DataLoader" />
      </service>
      <channels>
        <channel ref="http server" port="9000">
          <clientProviders>
            <formatter ref="soap" typeFilterLevel="Full" />
          </clientProviders>
          <serverProviders>
            <formatter ref="soap" typeFilterLevel="Full" />
          </serverProviders>
        </channel>
      </channels>
    </application>
  </system.runtime.remoting>
</configuration>


互相传递的列表对象就是 Entity

客户端的代码为 
namespace Leeing.Webgps
{
    class program
    {
        static void Main(string[] args)
        {
            RemotingConfiguration.Configure(AppDomain.CurrentDomain.BaseDirectory + "\\RemoteClient.config", false);

            DataLoader obj = new DataLoader();

            Entity myentity = new Entity();
            myentity.testA = "aaa";
            myentity.testB= "bbb";

            Entity myentity2 = new Entity();
            myentity2 .testA = "aaa";
            myentity2 .testB= "bbb";

            Hashtable myhs = new Hashtable();

            myhs.Add("1", myentity);
            myhs.Add("2", myentity2);

            obj.setGpsinfo(myhs);
         }   
 }

配置文件为
<configuration>
  <system.runtime.remoting>
    <application name="RemoteClient">
      <client url="http://192.168.1.2:9000/RemoteServer">
        <wellknown type="Leeing.Web.DataLoader, WebGpsHolder"
          url="http://192.168.1.2:9000/RemoteServer/DataLoader" />
      </client>
      <channels>
        <channel ref="http client" port="9000">
          <clientProviders>
            <formatter ref="soap" typeFilterLevel="Full" />
          </clientProviders>
          <serverProviders>
            <formatter ref="soap" typeFilterLevel="Full" />
          </serverProviders>
        </channel>
      </channels>
    </application>
  </system.runtime.remoting>
</configuration>

web 客户端的代码与上面客户端的代码几乎一样
除了换成了获取列表的部分

     Hashtable geths = proxy.loadCurrList();

     foreach (DictionaryEntry de in geths)
     {
        Entity temp = (Entity)geths[de.Key];

         Console.WriteLine(temp.testA);
      }



目前情况是 , 服务器运行正常,对象列表set的客户端程序运行正常。就是在获取对象列表时会报错 

“ 此远程处理代理没有信道接收,这意味着服务器没有正在侦听的已注册服务器信道,或者此应用程序没有用来与服务器对话的适当客户端信道。”

实在不知道是怎么回事了。。。。
--------------------编程问答--------------------  大侠我觉得你的设计思路可能出现了一些问题,你通过get,set的方法来改变和得到字段,那么需要保证的是在同一个应用程序域里面并且set完之后对象还没有被释放的情况下在服务器端已经得到了这个值,否则这个对象释放掉了,也就没有意义了。
--------------------编程问答-------------------- 我在服务器端 用全局静态列表保存 set的时候将值赋给一个全局列表 取的时候从这里面取
这样应该没问题吧? --------------------编程问答-------------------- up
自己顶一下





补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,