簡體   English   中英

WCFData.Service1不實現接口成員

[英]WCFData.Service1 Does not implement interface member

我正在使用Visual Studio 2010遵循有關C#的WCF指南。我以為我所做的一切都正確,直到構建了解決方案並且遇到此錯誤。 有人可以告訴我該怎么做以及如何解決嗎? 又為什么會發生呢? 我對此還很陌生,因此任何幫助將不勝枚舉。

這是我的代碼。 錯誤出現在第一行Service1 : IService1 我確實看到了說明,但嘗試將service1更改為“ Hello”,但沒有運氣。

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();
                }
            }
        }
    }
}

您可以右鍵單擊接口IService1並選擇“實現接口”。

這會將適當的方法添加到您的類中。

然后檢查您的代碼中的簽名是否拼寫錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM