Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF 4.0 SOA Commit as Transcation

In WCF 4.0, How can I commit 3 different service operation as a single Transaction? (Commit in SOA)

I have 3 different WCF service like below, Each service method invokes DB operation

service1.CreateEmployee();

service2.SendSetupRequestForEmployee();

service3.GiveOfficePermissionToEmployee();

Even if one operation fails entire thing should be rolled back...any help appreciated.

like image 335
kayak Avatar asked Dec 18 '25 00:12

kayak


1 Answers

The short answer: Make your service calls under a TransactionScope, and make sure the calls themselves are set up to run under transactions.

TLDR read this article here.

Basically, you need to decorate your Operation Contract method as such:

[TransactionFlow(TransactionFlowOption.Allowed)]
void MyWcfServiceCall() {...}

and the service method call itself with:

[OperationBehavior(TransactionScopeRequired = true)]
void MyWcfServiceCall() {...}

and call under a TransactionScope

using (TransactionScope tx = new TransactionScope(TransactionScopeOption.RequiresNew)) {
    myServiceClient.MyWcfServiceCall();
    myOtherServiceClient.MyOtherWcfServiceCall();
    tx.Complete();
}

in your config file for the bindings, set transactionFlow to true:

<bindings>
    <wsHttpBinding>
        <binding name="MyServiceBinding" transactionFlow="true" ... />
    </wsHttpBinding>
</bindings>
like image 183
James King Avatar answered Dec 19 '25 15:12

James King



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!