错误1
' UserWcfService.userService'没有实现接口成员 ' UserWcfService.IuserService.Getuserdetails()&#39 ;. ' UserWcfService.userService.Getuserdetails()'无法实现 接口成员,因为它不是 上市。 C:\ Users \ ravi \ Documents \ Visual Studio 2013 \ Projects \ wcfservices \ UserWcfService \ UserWcfService \ userService.svc.cs 16 18 UserWcfService
userservice.svc.cs
代码:
namespace UserWcfService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "userService" in code, svc and config file together.
// NOTE: In order to launch WCF Test Client for testing this service, please select userService.svc or userService.svc.cs at the Solution Explorer and start debugging.
public class userService : IuserService
{
public string str = ConfigurationManager.ConnectionStrings["connstring"].ToString();
List<usertype> Getuserdetails()
{
List<usertype> userdetails=new List<usertype>();
SqlConnection conn = new SqlConnection(str);
{
conn.Open();
SqlCommand cmd = new SqlCommand("spgetdata", conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
for(int i=0; i<dt.Rows.Count; i++)
{
usertype objinfo = new usertype();
objinfo.name = Convert.ToString(dt.Rows[i]["name"]);
objinfo.gender = Convert.ToString(dt.Rows[i]["gender"]);
objinfo.dateofbirth = Convert.ToDateTime(dt.Rows[i]["dateofbirth"]);
objinfo.address = Convert.ToString(dt.Rows[i]["address"]);
objinfo.contactno = Convert.ToInt32(dt.Rows[i]["contactno"]);
objinfo.mailid = Convert.ToString(dt.Rows[i]["mailid"]);
userdetails.Add(objinfo);
}
}
conn.Close();
}
return userdetails;
}
public string newuser(usertype user)
{
string strmessage;
SqlConnection conn = new SqlConnection(str);
{
conn.Open();
SqlCommand cmd = new SqlCommand("spinsert", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@C_Users_Name", user.name);
cmd.Parameters.AddWithValue("@C_Users_Gender", user.gender);
cmd.Parameters.AddWithValue("@lC_Users_DOB", user.dateofbirth);
cmd.Parameters.AddWithValue("@C_Users_Address", user.address);
cmd.Parameters.AddWithValue("@C_Users_ContactNo", user.contactno);
cmd.Parameters.AddWithValue("@C_Users_MailID", user.mailid);
//cmd.Parameters.AddWithValue("@C_Users_RegisteredDate", userinfo.date);
int result = cmd.ExecuteNonQuery();
if(result==1)
{
strmessage = user.name + "details inserted succesfully";
}
else
{
strmessage = user.name + "Details not inserted";
}
conn.Close();
}
return strmessage;
}
}
}
和IUserService
代码:
namespace UserWcfService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IuserService" in both code and config file together.
[ServiceContract]
public interface IuserService
{
[OperationContract]
List<usertype> Getuserdetails();
[OperationContract]
string newuser(usertype user);
}
[DataContract]
public class usertype
{
[DataMember]
public string name { get; set; }
[DataMember]
public string gender { get; set; }
[DataMember]
public DateTime dateofbirth { get; set; }
[DataMember]
public string address { get; set; }
[DataMember]
public int contactno { get; set; }
[DataMember]
public string mailid { get; set; }
[DataMember]
public DateTime date { get; set; }
}
}
答案 0 :(得分:0)
默认情况下,所有接口方法都是公共的,因此您的类接口也需要公开。
答案 1 :(得分:0)
在此处查看您的错误的一个好方法是右键单击
中的IuserService$("#date-birth").on("keyup", function() {
var dt = moment(this.value, 'DD/MM/YYYY', true);
if( dt.isValid() ){
$('#datetimepicker1').data("DateTimePicker").date(dt);
}
});
去实现界面 - &gt;明确实现接口
这将创建实现您的接口的存根方法。您可以将代码放入其中,也可以调整适当的方法
这是一个使用上面描述的方法构建我的例子
editor.codeLens