【问题标题】:Unable to implicitly convert type cross solution无法隐式转换类型交叉解决方案
【发布时间】:2017-03-05 23:12:18
【问题描述】:

大家好,我是编程新手,我目前正在尝试创建一个 Web 服务来检索我的数据库中的客户信息,但目前我无法解决此错误,请有人帮助我

CustAccounts.svc.cs

public class CustAcc : ICustAccounts
    {
        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public List<CustAcc> GetCustAccJSON()

        {
            List<CustomerAccountDAL> abc = new List<CustomerAccountDAL>();
            CustomerAccountDAL caDAL = new CustomerAccountDAL();
            List<CustAcc> allAcc = new List<CustAcc>();
            allAcc = caDAL.retrieveCustAccount();

            //caDAL.retrieveCustAccount();
            return allAcc;
        }
    }

CustomerAccountDAL.cs

public List<CustAcc> retrieveCustAccount()
        {
            List<CustAcc> acc = new List<CustAcc>();
            using (SqlConnection myConnection = new SqlConnection(con))
            {
                string jString = "Select * from CustDB";
                SqlCommand jCmd = new SqlCommand(jString, myConnection);
                myConnection.Open();
                using (SqlDataReader rr = jCmd.ExecuteReader())
                {
                    while (rr.Read())
                    {
                        CustAcc accounts = new CustAcc();
                        custEmail = rr["custEmail"].ToString();
                        custPassword = rr["custPassword"].ToString();
                        acc.Add(accounts);
                    }
                    myConnection.Close();
                }
            }
            return acc;
        }

CustAcc.cs

public class CustAcc
    { 
        public string custFullName { get; set; }
        public string custPreferredName { get; set; }
        public string custPassword { get; set; }
        public string custEmail { get; set; }
        public string custPhoneNumber { get; set; }
        public string message { get; set; }


        public CustAcc(string custName, string custFullName, string custPreferredName, string custPassword, string custEmail, string custPhoneNumber)
        {
            this.custFullName = custFullName;
            this.custPreferredName = custPreferredName;
            this.custPassword = custPassword;
            this.custEmail = custEmail;
            this.custPhoneNumber = custPhoneNumber;
        }

        public CustAcc()
        {
            this.custEmail = custEmail;
            this.custPassword = custPassword;
        }
    }

【问题讨论】:

  • 什么是错误以及它发生在哪里,如果您给出一个简洁明了的问题,您的问题可以更快地解决
  • @AlfieGoodacre 它给了我这个错误“不能隐式转换类型” 'System.Collection.GenericList' 到 'System.Collection.GenericList' “

标签: c# asp.net web-services iis visual-studio-2015


【解决方案1】:

将您的 Model 类移动到它们自己的名为 Model 的程序集中,并在 WS 和网站程序集中引用该程序集。

您还需要在您的网站中设置服务引用以在模型程序集中查找服务类型(这是添加服务引用向导中的一个选项)。

【讨论】:

  • 对不起,我不明白你的意思?有没有参考资料
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-12-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多