I have a WCF data service and a wpf client consuming it.
I have surrounded each call to the dataservice in the client with try catch blocks. Here is an example where I create a product.
try
{
Product product = Product.CreateProduct(productName, productNumber);
context.AddToProduct(product);
context.SaveChanges();
}
catch (DataServiceRequestException dataServiceRequestException)
{
Handle(dataServiceRequestException);
}
This all works well – I get an exception for example when the product number already exists. My question is how do I recover in the client when such an exception has been thrown. In other words how do I implement the Handle()-method. If I for example just show a messagebox with the content of the error message, the next time I try to create a product the same error occurs. In other words how do I make the context forget that there was an error. I’ve been looking for a context.Clear() og context.Forget() but no such method seems to exist.
The trick was to add a finally-clause, and reinitialize the context.