How to handle a FaultException in WCF without interrupting the whole transaction?

I have a WCF service called as part of a transaction.

If the service is called twice (often during debugging) I want the FaultException service to be selected by the service, but the overall transaction must be successful .

 throw new FaultException("Duplicate action not allowed for " + 
                          msgIn.ActionType, new FaultCode("DUPE_ACTION"));

Since I am throwing a FaultException, will the transaction vote to abort it?

I plan to do this (transaction setup is complete and then reset the error), but I don’t even know if this will work. It also has some difficulties that I do not want to worry about.

[OperationBehavior(TransactionScopeRequired = true,
                   TransactionAutoComplete = false)]
public void MyMethod(...)
{
   try
   {
      OperationContext.Current.SetTransactionComplete( );
      throw new FaultException("Duplicate action not allowed for " + 
                          msgIn.ActionType, new FaultCode("DUPE_ACTION"));
   }
   catch
   {
      /* Do some error handling then */
      throw;
   }
}

Success - , , - , .

, . , .

WCF , ?

+2

Source: https://habr.com/ru/post/1792855/


All Articles