我正在尝试为我的btnUpdate书类创建faultexception。我是WCF的新手,我不确定我必须添加异常消息客户端或服务的哪个部分?
这是我的客户部分
protected void BtnUpdateBook(object sender, DirectEventArgs e)
{
Service1Client client = new Service1Client();
ConcreteBook book = new ConcreteBook
{
BookId = Convert.ToInt32(txtBookId.Text),
BookName = txtBookName.Text,
BookDescription = txtBookDescription.Text
};
client.UpdateBook(book);
strBook.DataSource = client.GetAll();
strBook.DataBind();
client.Close();
}
这是服务
public class UpdateBook
{
public void BookUpdate(ConcreteBook book)
{
BookEntities db = new BookEntities();
Book upBook = db.Books.FirstOrDefault(x => x.bookId == book.BookId);
upBook.bookName = book.BookName;
upBook.bookDescription = book.BookDescription;
db.SaveChanges();
}
}
修改
我在Service
中创建了BSException类[DataContract]
public class BSException
{
private int id;
[DataMember]
public int Id
{
get { return id; }
set { id = value; }
}
private string exceptionMessage;
[DataMember]
public string ExceptionMessage
{
get { return exceptionMessage; }
set { exceptionMessage = value; }
}
}
我正在尝试在我的服务中的updatebook类中使用这个类
public void BookUpdate(ConcreteBook book)
{
BookEntities db = new BookEntities();
try
{
Book upBook = db.Books.FirstOrDefault(x => x.bookId == book.BookId);
upBook.bookName = book.BookName;
upBook.bookDescription = book.BookDescription;
db.SaveChanges();
}
catch(Exception)
{
BSException exception = new BSException();
//exception. //problem is here??
}
}