简体   繁体   中英

WCFData.Service1 Does not implement interface member

I am following a guide on WCF on C# using visual studio 2010. I thought I was doing everything correct, till I built the solution and I am meet with this error. Can someone tell me what to do and how to fix it? Also why its happening? I am fairly new to this, so any help will be greatly appericated.

This is my code. The error appears in the first line, in Service1 : IService1 . I do see the note but I tried changing service1 to say "Hello" but no luck.

namespace WCFData
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu
    // to change the class name "Service1" in both code
    // and config file together.
    public class Service1 : IService1
    {
        SqlConnection conn;
        SqlCommand comm;

        SqlConnectionStringBuilder connStringBuilder;
        void ConnectToDB()
        {
            connStringBuilder = new SqlConnectionStringBuilder();
            connStringBuilder.DataSource = "NATHAN-PC\\SQLEXPRESS";
            connStringBuilder.InitialCatalog = "WCF";
            connStringBuilder.Encrypt = true;
            connStringBuilder.TrustServerCertificate = true;
            connStringBuilder.ConnectTimeout = 30;
            connStringBuilder.MultipleActiveResultSets = true;
            connStringBuilder.IntegratedSecurity = true;

            conn = new SqlConnection(connStringBuilder.ToString());
            conn = conn.CreateCommand();


        }

        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }

        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            if (composite == null)
            {
                throw new ArgumentNullException("composite");
            }
            if (composite.BoolValue)
            {
                composite.StringValue += "Suffix";
            }
            return composite;
        }

        public int InsertPerson(Person p)
        {

            try
            {
                comm.CommandText = "INSERT INTO Person Values(@Id, @Name, @age)";
                comm.Parameters.AddWithValue("Id", p.Id);
                comm.Parameters.AddWithValue("Name", p.Name);
                comm.Parameters.AddWithValue("Age", p.Age);

                comm.CommandType = CommandType.Text;
                conn.Open();

                return comm.ExecuteNonQuery();


            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }
    }
}

You can right click on the interface IService1 and select "Implement Interface."

This will add the appropriate methods to your class.

Then check if you are misspelling their signatures in your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM