I have a WCF service that use Exceptions to returns wrong results. for example when a argument of method is wrong an exception raised and send a exception to a client and client catch that exception and show its message. I use FaultException too. but the problem is the destructor of service class doesn't called when an exception raised. I must dispose the repository in the destructor when exceptions occured. how can I do it?
public class TestService : ITestService
{
private AccountReposiory _accountReposiory;
public TestService()
{
Console.WriteLine("Started!");
_accountReposiory = new AccountReposiory();
}
public void DoWork()
{
//Exception Occurred!;
throw new Exception("Some Exception");
//...
}
~TestService()
{
Console.WriteLine("Finished!");
_accountReposiory.Dipose();
}
}