WCF 4.0 SOA Commit as Transcation

In WCF 4.0, how can I commit 3 different service operations as a single transaction? (Commit in SOA)

I have 3 different WCF services as shown below. Each service method invokes a DB operation

service1.CreateEmployee();

service2.SendSetupRequestForEmployee();

service3.GiveOfficePermissionToEmployee();

Even if one operation failed, the whole thing should be thrown back ... any help is appreciated.

+3
source share
1 answer

Short answer: make your service calls under TransactionScopeand make sure that the calls themselves are configured to work under transactions.

TL; DR read this article here .

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

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

:

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

TransactionScope

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

, transactionFlow true:

<bindings>
    <wsHttpBinding>
        <binding name="MyServiceBinding" transactionFlow="true" ... />
    </wsHttpBinding>
</bindings>
+5

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


All Articles