Nathan De Lima Nathan De Lima - 3 months ago 17
C# Question

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.

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


}

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.

Answer

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.

Comments