none
Require enable DTC in client when calling WCF with transaction RRS feed

  • Question

  • Hi guys,

    I'm developing a demo application which includes:

    Server #1: 1 SQL Server ==> Enabled DTC Security (Network DTC Access/ Allow Inbound/ Allow Outbound/  No Authentication Required)

    Server #2: 1 Web Server, which host a WCF service in IIS, insert/update data in DB Server #1. This WCF service supports transaction (TransactionFlowOption.Mandatory) ==> Enabled DTC (Network DTC Access/ Allow Inbound/ Allow Outbound/  No Authentication Required)

    PC #3: 1 Windows 7 PC runs client app which invoke WCF (via https) and using TransactionScope, such as

    using (var tranScope = new TransactionScope())
                    {
                        DocumentServiceClient client = new DocumentServiceClient(); 
                        client.PlaceOrder(); 
                        client.AdjustInventory(); 
                        tranScope.Complete();
                    }

    My current issue is if I don't enable DTC (Network DTC Access/ Allow Inbound/ Allow Outbound/  No Authentication Required) , client App will throw exception (MSDTC Transaction). So there is really inconvenient because end-user must configure (DTC) their machine before using app.

    May you let me idea to require less configuration on client side when I need to call WCF API in Transaction Scope ?. It's great if client-side don't need to configure anything and WCF server will take care the DTC.

    Regards,


    Tuesday, May 12, 2015 1:44 AM

Answers

  • May you let me idea to require less configuration on client side when I need to call WCF API in Transaction Scope ?. It's great if client-side don't need to configure anything and WCF server will take care the DTC.

    DTC is machine to machine. The tranasction should be started and completed on the Web server in a DAL using transactions to be in DTC with the SQL Server machine. WCF in this situation does not need to be in a transaction started from the client, and the client should not be invloving any transactions on its side. The DAL is referenced in the WCF service, and DAL methods start the transaction and completes it.

    Tuesday, May 12, 2015 8:24 PM
  • I think that you need to refactor both client and server side such that there is no need to use a transaction on the client. If that means more methods are needed on the server (methods that combine actions wrapped in a transaction, before returning to the client), then that's what you'll have to do.

    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Wednesday, May 13, 2015 4:00 PM
    Moderator

All replies

  • May you let me idea to require less configuration on client side when I need to call WCF API in Transaction Scope ?. It's great if client-side don't need to configure anything and WCF server will take care the DTC.

    DTC is machine to machine. The tranasction should be started and completed on the Web server in a DAL using transactions to be in DTC with the SQL Server machine. WCF in this situation does not need to be in a transaction started from the client, and the client should not be invloving any transactions on its side. The DAL is referenced in the WCF service, and DAL methods start the transaction and completes it.

    Tuesday, May 12, 2015 8:24 PM
  • Hi DA924,

    My services require to support calling api both individual and combination (in transaction). Let see an example

    public class MyServices
        {
            public void ADD();
            public void UPDATE();
            public void DELETE();
        }

    Client App (which invoke APIs) support users to actions (edit/update/delete). If user only add smt => Client app only invoke a single ADD api. If user do multi-actions, such as Update + Delete ==> Client app need to invoke both UPDATE + DELETE in a transaction scope.

    There are a ton of possible combination may appears when there are a large number of APIs in the services. Therefore it is not good to create wrapper APIs due to the trade off of duplication code in service layer, such as UPDATEandDELETE as bellow 

    public class MyServices
        {
            public void ADD();
            public void UPDATE();
            public void DELETE();
    
            public void UPDATEandDELETE();
        }

    Please let me clear about your idea.

    Wednesday, May 13, 2015 4:18 AM
  • The only way you are going to come around it is client, WCF Web service, and server database machines need to have DTC enabled on all machines with the proper handshake.
    Wednesday, May 13, 2015 3:45 PM
  • I think that you need to refactor both client and server side such that there is no need to use a transaction on the client. If that means more methods are needed on the server (methods that combine actions wrapped in a transaction, before returning to the client), then that's what you'll have to do.

    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Wednesday, May 13, 2015 4:00 PM
    Moderator
  • I'll just say one other thing. What you are trying to do is not started on the client side using WCF in a transactional state, unless the client is a DAL in an application that inclued WCF metods in a transaction with the database machine with all machines using DTC.  
    Wednesday, May 13, 2015 7:26 PM