locked
Wcf Transaction using Services RRS feed

  • Question

  • User-665281982 posted

    I want to known which one (s) would be the best solution in this scenario.

    1) Invoke the Service 1 that invoke business rules BLL, which will then access the DAL layer to perform CRUD operations.

    2) Shortly thereafter, the service 2 will be invoked , which will also make access to BLL and then access the DAL for CRUD.

    If an exception occurs in the execution of the operation of the Service 2 for example.

    Can I  implement so that everything that was done before will be undone, including operations of the service 1 ?

    Any sugestions ?


    thank you

    Wednesday, February 6, 2013 6:47 AM

Answers

  • User220959680 posted

    WCF Transactions

    Here is an example http://www.codeproject.com/Articles/38793/6-Steps-to-Enable-Transactions-in-WCF

    //1. Add TransactionFlow attribute to Service operations
    
    [ServiceContract]
    public interface IService1
    {
    [OperationContract]
    [TransactionFlow(TransactionFlowOption.Allowed)]
    void UpdateData();
    }
    
    //2. Add TransactionScopeRequired attribute to Service operation implementation
    [OperationBehavior(TransactionScopeRequired = true)]
    public void UpdateData()
    {
    //
    }
    
    
    //3.Enable transactionFlow for bindings in config
    <bindings>
    <wsHttpBinding>
    <binding name="TransactionalBind" transactionFlow="true"/>
    </wsHttpBinding>
    </bindings>
    
    //4. Attach binding to the end point
    <endpoint address="" binding="wsHttpBinding" 
    	bindingConfiguration="TransactionalBind" contract="WcfService1.IService1">
    
    //5. Call the both services under Transaction scope
    using (TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew))
    {
    try
    {
    ServiceReference1.Service1Client obj = new ServiceReference1.Service1Client();
    obj.UpdateData();
    ServiceReference2.Service1Client obj1 = new ServiceReference2.Service1Client();
    obj1.UpdateData();
    ts.Complete();
    }
    catch (Exception ex)
    {
    ts.Dispose();
    }
    }



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 8, 2013 6:28 AM