WCFD数据.Service1不实现接口成员
本文关键字:接口 成员 实现 数据 Service1 WCFD | 更新日期: 2023-09-27 18:01:04
我正在使用visual studio 2010遵循关于C#上WCF的指南。我以为我做的每件事都是正确的,直到我建立了解决方案,我遇到了这个错误。有人能告诉我该怎么做以及如何修复它吗?为什么会发生这种情况?我对这件事还很陌生,所以任何帮助都会非常重要。
这是我的密码。错误出现在Service1 : IService1
中的第一行。我确实看到了纸条,但我试着把service1改为说"你好",但没有成功。
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
并选择"Implement interface">
这将向类中添加适当的方法。
然后检查您是否在代码中拼错了他们的签名。