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;
那里有webservice调用,还有一些数据库日志记录。我知道没有神奇的方法可以“撤消”对外部供应商的Web服务调用,但是如果数据库日志失败,我如何防止数据库日志与事务一起回滚?如果我已经进行了网络服务电话,我该怎么办?我这太难了吗?我不想向客户开账单,然后无法为他们削减支票,或者更糟糕的是(在我的组织看来),给他们削减支票但是没有为他们的账户开账单!
答案 0 :(得分:0)
我知道这有点晚了但你实现这样的事情的唯一方法就是使用像NServiceBus这样的东西。
看看http://andreasohlund.net/2009/08/24/achieving-consistency-using-nservicebus/ 它提供了一个类似要求的例子