我試圖在visual studio 2010中創建演示WCF webservice;我已經成功添加了thr服務引用,但客戶端上仍有問題。如果我嘗試在服務中調用某個函數,則會出現錯誤。在.net中調用WCF webservices函數時出錯
這裏是我的代碼:
namespace BankAccount
{
[ServiceContract]
public interface IUserServices
{
[OperationContract]
bool addNewUser(User user);
}
}
namespace BankAccount
{
public class UserServices : IUserServices
{
public bool addNewUser(User user)
{
SqlConnection conn = null;
SqlCommand cmd = null;
try
{
String sql = "insert into user(username,password,isActive) values(@username,@password,@isActive)";
conn = Connection.getConnection();
conn.Open();
cmd = new SqlCommand(sql, conn);
cmd.Parameters.Add(new SqlParameter("@username", user.getUsername()));
cmd.Parameters.Add(new SqlParameter("@password", user.getPassword()));
cmd.Parameters.Add(new SqlParameter("@password", user.getActive()));
}
catch (SqlException ex)
{
return false;
throw ex;
}
finally
{
cmd.Dispose();
conn.Close();
conn.Dispose();
}
return true;
}
}
}
//用戶對象
public class User
{
private int Id;
private String username;
private String password;
private Boolean isActive;
public User()
{
}
public int getId()
{
return this.Id;
}
public void setId(int id)
{
this.Id = id;
}
public String getUsername()
{
return this.username;
}
public void setUsername(String username)
{
this.username = username;
}
public String getPassword()
{
return this.password;
}
public void setPassword(String password)
{
this.password = password;
}
public Boolean getActive()
{
return this.isActive;
}
public void setActive(Boolean isActive)
{
this.isActive = isActive;
}
}
的客戶端站點
using System.Web.UI.WebControls;
using BankClient.ServicesForUser;
namespace BankClient.userclient
{
public partial class usersaving : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSave_Click(object sender, EventArgs e)
{
UserServicesClient client = new UserServicesClient();
//User on client project
User user = new User();
user.setUsername(txtusername.Text);
user.setPassword(txtpassword.Text);
user.setActive(true);
bool result = client.addNewUser(user);
}
}
}
我上以下行錯誤:
client.addNewUser(user)
錯誤:
the best overloaded method match for 'Bank.Client.ServicesName.UserServicesClient.addNewUser(Bank.Client.ServicesName.User) has some invalid arguments
有沒有人有一個想法,這個問題可能是什麼?
什麼錯誤究竟是什麼?你嘗試解決這個問題? – CodeCaster
Downvote出於上述確切原因:**什麼**錯誤?你有什麼嘗試? –
您好男人,你沒有看到我說「我嘗試創建演示」由C#?我有問題,我無法解決,因此我張貼在這裏找到解決方案,它不適合jocking。 –