I've got a WCF service, which contains a Entity Framework model. My class has a timestamp attribute, so conflicting updates should throw an OptimisticConcurrencyException. My question is, what's the best way to pass this exception to the client, without assuming that the client is .NET?
So, I will skeleton out one approach, that I think demonstrates the problem. Here is a WCF service with an async method:
[ServiceContract]
public interface ICarService
{
[OperationContract]
[FaultContract(typeof(OptimisticConcurrencyException))]
Task UpdateCarAsync(Car obj);
}
Then, here is a ASP.NET MVC client:
try {
await this.repo.UpdateCarAsync(theCar);
}
catch (FaultException<OptimisticConcurrencyException>) {
ModelState.AddModelError(string.Empty, "Optimistic Concurrency Exception");
}
In this case the client to the WCF service knows about OptimisticConcurrencyException because it is already a .NET client. But, what if this was being called from some other language? Shouldn't there be some kind of abstraction of OptimisticConcurrencyException?
I think I'm really missing something here. So, a proper example would be helpful.