【发布时间】:2011-05-31 18:49:34
【问题描述】:
我对 silverlight 和 WCF 完全陌生。仍在阅读在线资料并尝试编写一些代码以开始工作。 :)
我的问题是,我想将数据插入数据库并且我的插入方法返回一个布尔值。如何在按钮单击事件中捕获 Silverlight 中的返回值并向用户显示确认消息。
我的服务代码是:
[OperationContract]
public bool insertData(string Name, string Address, string cType, string postcode, string city, string phone, string email)
{
bussAppDataContext dc = new bussAppDataContext();
TestTable tt = new TestTable();
tt.CompanyName = Name;
tt.Address = Address;
tt.CompanyType = cType;
tt.Postcode = postcode;
tt.City = city;
tt.Telephone = phone;
tt.Email = email;
dc.TestTables.InsertOnSubmit(tt);
dc.SubmitChanges();
return true;
}
silverlight 客户端代码是:
private void btnSend_Click(object sender, System.Windows.RoutedEventArgs e)
{
FirstServiceReference.FirstServiceClient webServc = new FirstServiceReference.FirstServiceClient();
webServc.insertDataAsync(txtCName.Text.Trim(), txtAddress.Text.Trim(), cmbCType.SelectedValue.ToString(), txtPostcode.Text.Trim(), txtCity.Text.Trim(), txtPhone.Text .Trim(), txtEmail.Text.Trim());
}
【问题讨论】:
标签: silverlight wcf