I have the following scenario :
A WCF
Client starts and propagates a transaction to a WCF Service using a TransactionScope.
The client contract is the following :
public interface IMyService
{
[OperationContract]
[FaultContract(typeof(MyException))]
[TransactionFlow(TransactionFlowOption.Mandatory)]
bool DoSomeTransactionalWork();
[OperationContract]
[FaultContract(typeof(MyException))]
bool DoSomeWork();
}
The proxy used is not generated, it is based on the well known wrapper :
using (TransactionScope ts = new TransactionScope())
{
Service<IMyService>.Use(proxy =>
{
proxy.DoSomeTransactionalWork();
});
}
The WCF Service method, which requires a transaction in the contract definition and votes implicitly for it, throws a FaultException<MyException>
.
[OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
public bool DoSomeTransactionalWork()
{
throw new FaultException<MyException>(new MyException(myMessage));
}
The WCF proxy receives a TransactionAbortedException
with InnerException
set to null therefore losing the WCF Fault.
try
{
using (TransactionScope ts = new TransactionScope())
{
Service<IMyService>.Use(proxy =>
{
proxy.DoSomeTransactionalWork();
});
}
}
catch (TransactionAbortedException tae)
{
// tae.InnerException is null
}
In a similar scenario where a Transaction isn't required by the contract for a service method :
public bool DoSomeWork()
{
throw new FaultException<MyException>(new MyException(myMessage));
}
and the client simply calls it via the same proxy code, a FaultException<MyException>
is received.
try
{
Service<MyService>.Use(proxy =>
{
proxy.DoSomeWork();
});
}
catch (FaultException<MyException> tae)
{
//
}
Am I missing something or is it the expected behavior
?
TIA.
EDIT 1
There is no problem at all with this synchronous call in client code.
HOWEVER, you may encounter the behavior I describe if you're making an incorrect asynchronous call when working with the APM. See my response.