【发布时间】:2010-11-28 12:16:00
【问题描述】:
I've already looked here 并找到了一些关于管理交易的好建议。
我的问题是,至少在一种情况下,我还调用了 Web 服务,将日志记录到数据库表中。以下是一些可能有助于使事情更清楚的伪代码:
customer = batchRefundToProcess.RefundCustomer;
//Validate everything
if (ValidateRefund(batchRefundToProcess) == false)
{
refund.RefundStatusId = (int)REFUNDSTATUSES.RefundDenied;
refund.ReviewedBy = displayUserName;
refund.Update();
return false;
}
//get this customer's payments
List<RefundTran> trans = customer.ARTransactions;
refund.RefundStatusId = (int)REFUNDSTATUSES.RefundInProcess;
refund.ReviewDate = DateTime.Now;
refund.ReviewedBy = displayUserName;
refund.Update();
List<RefundTran> paperTransactions = new List<RefundTran>();
foreach (RefundTran transaction in trans)
{
if (customer.Balance < 0) //balance is negative if we owe them money
{
//processtransaction has the following side effects:
//1. refund detail is created for the tran
//2. customer is billed for the refunded amount, web service is called
var paperTransaction = processTransaction(customer, transaction, refund);
if (paperTransaction != null) //this transaction qualifies for a paper check for one reason or another
{
paperTransactions.Add(paperTransaction);
}
}
}
//get total amount
//basically, the sum total of all their paper check transactions plus whatever's left on their balance, if anything
decimal paperCheckAmount = paperTransactions.Sum(pt => pt.Amount) - customer.Balance;
if (paperTransactions.Count > 0)
{
//cut a check for all the transactions together
AddLineToFile(customer, paperCheckAmount, paperTransactions.First(), REFUNDFILETYPE.ElectronicCheck, refund.RefundId);
}
refund.RefundStatusId = (int)REFUNDSTATUSES.RefundApproved;
refund.ReviewedBy = displayUserName;
refund.Update();
} //end using block
return true;
那里有网络服务调用,还有一些数据库日志记录。我知道没有什么神奇的方法可以“撤消”对外部供应商的 Web 服务调用,但是如果数据库日志记录失败,如何防止数据库日志记录与事务一起回滚呢?如果我已经进行了 web 服务调用,我应该怎么做?我做这太难了吗?我不想给客户开账单,然后给他们开支票失败,或者更糟(在我的组织看来),给他们开支票但给他们的账户开票失败!
【问题讨论】:
标签: c# transactions data-access-layer