执行此方法调用的事务被异步中止.

问题描述:

客户端代码:

//// Below Code specifically used for TxnScope Options
            using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.Required))
            {
                dataFromService = proxy.TestTxnScopeOptions();
                if (Transaction.Current != null)
                {
                    stringBuilder.Append("Client LocalIdentifier: " + Transaction.Current.TransactionInformation.LocalIdentifier);
                    stringBuilder.Append("\nClient DistributedIdentifier: " + Transaction.Current.TransactionInformation.DistributedIdentifier);

                    ////stringBuilder.Append("\nClient Transaction protocol: " + netTcpBinding.TransactionProtocol.ToString());
                }
                else
                {
                    stringBuilder.Append("No transaction in client");
                }
                transactionScope.Complete();
            }


服务器端代码:

[OperationBehavior(TransactionScopeRequired = true)]
        public string TestTxnScopeOptions()
        {
            StringBuilder stringBuilder = new StringBuilder();

            using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.Required))
            {
                if (Transaction.Current != null)
                {
                    stringBuilder.Append("Service LocalIdentifier (Inside Transaction Scope): " + Transaction.Current.TransactionInformation.LocalIdentifier);
                    stringBuilder.Append("\nService DistributedIdentifier (Inside Transaction Scope): " + Transaction.Current.TransactionInformation.DistributedIdentifier);
                }
                else
                {
                    stringBuilder.Append("No transaction in service");
                }
            }
            stringBuilder.Append("Service LocalIdentifier(Outside Transaction Scope): " + Transaction.Current.TransactionInformation.LocalIdentifier);
            stringBuilder.Append("\nService DistributedIdentifier(Outside Transaction Scope): " + Transaction.Current.TransactionInformation.DistributedIdentifier);
            return stringBuilder.ToString();
        }

服务器端代码成功执行,但是在返回时,它引发异常此方法调用在其下执行的事务被异步中止."我了解,已经有提及的主题 例外,但没有一个解释真正的原因.

The server side code executes successfully, however, upon return, it throws the exception " The transaction under which this method call was executing was asynchronously aborted." I understand, there has been threads already for mentioned exception, but none of it explains the actual reason. 

有什么想法吗?

Any thoughts?

谢谢!

在这里要小心!如果您设置TransactionAutoComplete = true,那么如果服务正常返回,则将提交事务.仅当存在未处理的异常时(在大多数情况下您没有该异常,因为您正在捕获异常并返回 收据消息),交易将被回滚.请参见 http://msdn.microsoft.com/zh-CN/library/system.servicemodel.operationbehaviorattribute.transactionautocomplete.aspx .

Be careful here! If you set TransactionAutoComplete=true then if the service returns normally the transaction will be committed. Only if there is an unhandled exception (which for the most part you don't have because you are catching exceptions and returning a receipt message) will the transaction be rolled back.  See http://msdn.microsoft.com/en-us/library/system.servicemodel.operationbehaviorattribute.transactionautocomplete.aspx

还请检查那些类似的线程:
http://*. com/questions/11900387/如何预防交易范围引发的异常我已经处理过.

Also please check those similar threads:
http://*.com/questions/11900387/how-to-prevent-transaction-scope-from-throwing-an-exception-i-have-already-handl .

http://*.com/questions/6748738/why-isnt-this-transaction -isolated  .

谢谢.