当前位置: 代码迷 >> Web Service >> webservice 为何不能强制转换
  详细解决方案

webservice 为何不能强制转换

热度:127   发布时间:2016-05-02 02:21:19.0
webservice 为什么不能强制转换
webservice  

 [WebMethod(Description = "aa")]
        public  CustomerDeviceInfoEntity GetNamefromCustomerid(int customerid)
        {
            CustomerDeviceInfoEntityCollection coll = CustomerDeviceInfoEntity.SelectWhere(" customerid='" + customerid + "'");
            if (coll.Count > 0)
                return coll[0];
            else
                return null;
        }


调用页 
  CustomerDeviceInfoEntity ent = new CustomerDeviceInfoEntity();
            ent  = (CustomerDeviceInfoEntity)web.GetNamefromCustomerid(11);
            this.TextBox1.Text = ent.RecordDateTime.ToString();

编译后提示错误 
无法将类型“DemoWeb.localhost.CustomerDeviceInfoEntity”转换为“IDH.DAO.CustomerDeviceInfoEntity” D:\mxy\DemoWeb\DemoWeb\WebForm1.aspx.cs 48 18 DemoWeb

请问这个怎么调用啊


------解决方案--------------------
错误提示很明显嘛. 
CustomerDeviceInfoEntity 这个类, WebService端和你的调用页要使用的是同一个引用.
你的代码里出现了两个(命名空间不同). 故而不能转换.
DemoWeb.localhost.CustomerDeviceInfoEntity
IDH.DAO.CustomerDeviceInfoEntity
------解决方案--------------------
你检查下看看了,如果是同一个DLL, 咋会出现命名空间不同的情况呢.(鼠标放在类名上智能提示,看全名是否一样). 另忘说了,就是CustomerDeviceInfoEntity  这个类必须支持序列化,才可以在webService传输.
  相关解决方案