错误歧义和缺少部分修饰符

时间:2012-06-12 10:03:36

标签: c# wcf windows-phone-7

我只关注http://www.dotnetcurry.com/ShowArticle.aspx?ID=585 做项目,但有错误歧义和缺少部分修饰符。

我在Iservice1.cs的代码

namespace WCT_DataServiceApp
{
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        ImageEmployee GetEmpByEmpNo(int EmpNo);
    }

    [DataContract]
    public class ImageEmployee
    {
        [DataMember]
        public int EmpNo { get; set; }
        [DataMember]
        public byte[] EmpImage { get; set; }
    }
}

和Service1.svc.cs上的代码

namespace WCT_DataServiceApp
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    public class Service1 : IService1
    {
        public ImageEmployee GetEmpByEmpNo(int EmpNo)
        {
            var Conn = new SqlConnection(@"Data Source=yeo-pc\sqlexpress;Initial Catalog=image;Integrated Security=True");
            Conn.Open();
            var Cmd = new SqlCommand();
            Cmd.Connection = Conn;
            Cmd.CommandText = "Select * from ImageEmployee where EmpNo=@EmpNo";
            Cmd.Parameters.AddWithValue("@EmpNo", EmpNo);

            var Reader = Cmd.ExecuteReader();

            ImageEmployee objImgEmp = new ImageEmployee();

            while (Reader.Read())
            {
                objImgEmp.EmpNo = Convert.ToInt32(Reader["EmpNo"]);
                objImgEmp.EmpImage = (byte[])Reader["EmpImage"];
            }
            Reader.Close();
            Conn.Close();
            return objImgEmp;
        }
    }
}

1 个答案:

答案 0 :(得分:0)

您的解决方案中似乎已经有了Service1个课程。如果您在新的WCF项目中尝试它,那么默认情况下,您将获得两个文件,一个用于接口,一个用于类,命名为:IService1.csService1.cs。您需要删除这两个或用您的代码替换它们。该错误要求您使用partial,这是用于Partial类,因为它假定您在新代码文件中定义了部分类Service1