从事务范围调用WCF服务方法

Dej*_*ejo 2 .net c# wcf transactions transactionscope

我的代码如下:

    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();
      }
Run Code Online (Sandbox Code Playgroud)

我的问题是,我可以在Transaction范围内调用WCF服务方法而没有任何问题吗?(我不知道服务方法是如何实现的)另外,我想要避免Transaction不会涉及wcf服务方法调用.

jle*_*lew 8

WCF服务方法可以是事务性的,也可以不是,具体取决于它们的实现方式.如果要确保服务调用不参与事务,请将服务调用包装在"已禁止"的事务范围中.这将抑制任何环境事务.

using( new TransactionScope(TransactionScopeOption.Suppress) 
{
    WcfServiceInstance.SomeMethod()
}
Run Code Online (Sandbox Code Playgroud)

  • 这也解决了问题并且非常有用 (2认同)