2

私は次のようなコードを持っています:

    using (TransactionScope scope = TransactionScopeFactory.CreateTransactionScope())
      {

        *// some methodes calls for which scope is needed*
        ...
        ...
        *//than WCF method code for which I don't want transaction to be involved, but if it throws  an exception I don't wish scope to be completed*
        WcfServiceInstance.SomeMethod();
        scope.Complete();
      }

私の質問は、Transaction スコープ内で問題なく WCF サービス メソッドを呼び出すことはできますか? (サービス メソッドがどのように実装されているかはわかりません) また、wcf サービス メソッドの呼び出しに Transaction が関与しないことを確認したいと思います。

4

2 に答える 2

8

WCF service methods can be transactional or not, depending on how they are implemented. If you want to be sure that your service call does not participate in the transaction, wrap the service call in a "suppressed" transaction scope. This will suppress any ambient transaction.

using( new TransactionScope(TransactionScopeOption.Suppress) 
{
    WcfServiceInstance.SomeMethod()
}
于 2012-11-01T13:27:28.287 に答える
4

To propagate a transaction from your client application ot the service you need to explicity opt-in to transaction flows on the serer and client. If your client is using a transaction aware binding (NetTcp, NetNamedPipe, WSHttp, WSDualHttp, & WSFederation) then you should see a boolean property TransactionFlow. Setting this to false will prevent any transactions from flowing from your cient to the server.

You get some additional control on the operation level with the TransactionFlow attribute, but this is a server side attribute, so if you don't have access to the service code this likely isn't an option.

Please let me know if the TransactionFlow attribute doesn't solve your problem. Understand that setting this to false on the client will prevent any & all transactions from being passed from client to service for that particular endpoint binding.

于 2012-11-01T13:27:34.120 に答える