0

I am trying to create faultexception for my btnUpdate book class. I am new in WCF and I am not sure which part I have to add exception message client or service?

This is my Client part

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();
}

And this is service

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();
    }
}

Edit

I create BSException class in Service

[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; } 
    }
}

and I am trying to use this class in my updatebook class in service

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??
    }
}
CDspace
  • 2,639
  • 18
  • 30
  • 36
Ilaria
  • 167
  • 2
  • 13
  • Both have to know the Exception. The Service throws it and the Client must react to it. – Rabban Oct 14 '16 at 12:47
  • Please add this information to your Question. Its nearly impossible to read in the comments. And make your question more clear. I'm still not really sure what you want to know. – Rabban Oct 14 '16 at 13:12
  • Sorry i am new in this site thats why i couldnt add my code clearly. – Ilaria Oct 14 '16 at 13:23
  • 1
    No Problem, mate. But please update your Question with your posted code in the comments. Then it's more visible to all who view your question. To mark text as code, use ` instead of ' – Rabban Oct 14 '16 at 13:31
  • sorry @Raban i dont understan what i have to do when i will add my code to text area? – Ilaria Oct 14 '16 at 13:47
  • Possible duplicate of [WCF FaultException](https://stackoverflow.com/questions/22072455/wcf-faultexception) – Cœur Dec 13 '18 at 07:14

0 Answers0