我无法使COM +使用WCF服务的同一事务 [英] I can't make a COM+ use the same transaction of my WCF service
问题描述
我正在创建与COM +通信的WCF服务,并且COM +进行数据验证并访问数据库.
I'm creating a WCF service that communicates with a COM+, and that COM+ does the data validations and accesses the database.
我按如下方式使用COM +:
I use the COM+ as follows:
Type oInterfaceUnicaType = System.Type.GetTypeFromProgID("InterfaceUnica.Interface", System.Configuration.ConfigurationManager.AppSettings["ServidorInterfaceUnica"], true);
这样,我可以访问所有COM +属性,方法等.
This way I can access all the COM+ attributes , methods , etc.
在我的BLL中有这段代码:
In my BLL there is this piece of code:
using (var transaction = new TransactionScope())
{
foreach (Pagamento pagamento in pagamentos)
{
if (pagamento.acao == Acao.ENVIO)
{
//Pagamentos terão a consulta de saldo um a um , depois serão enviados
if (pagamento.confereSaldo.Value)
{
Boolean saldoParaPagamento = ocb.consultaSaldo(pagamento);
logger.Info("PagamentoBLL - Verificando se Tem saldo para pagamento!{0}", saldoParaPagamento);
if (!saldoParaPagamento)
{
throw new FaultException<ErroRetorno>(new ErroRetorno(pagamento.origem, "Saldo insuficiente para o Pagamento!", TipoErro.NEGOCIO, 30), new FaultReason("Saldo insuficiente para o Pagamento!"));
}
}
iu.exportaPagamento(pagamento);
}
else if (pagamento.acao == Acao.CANCELAMENTO)
{
iu.cancelaPagamento(pagamento);
}
}
logger.Info("PagamentoBLL - ProcessaPagamentos - Commitando a transação");
transaction.Complete();
}
logger.Trace("PagamentoBLL - Encerrando ProcessaPagamentos");
return true;
}
catch (FaultException<ErroRetorno> ex)
{
logger.Fatal(ex, "Erro ao Processar os Pagamentos");
throw ex;
}
catch (Exception ex)
{
logger.Fatal(ex.StackTrace);
throw ex;
}
我认为,使用transactionScope中指定的事务可以很好地工作(服务的web.config和客户端的app.config都可以).但是,当我使用付款清单时,第一次付款是完美的,应该在数据库中输入(iu.exportaPagamento(pagamento);
被调用并使用COM +方法),第二次付款调用相同的方法,该错误被抛回到我的WCF服务中,并且行"transaction.Complete();"尚未达到,但是数据库更改没有回滚.怎么做
我使这些更改回滚吗?如果我的代码不是最适合这种情况的代码,请也进行注释
谢谢,
I thought it would work well, using the transaction specified in the transactionScope (both service's web.config and client's app.config are OK). But when I use a List of payments, where the first payment is perfect and should enter in database (iu.exportaPagamento(pagamento);
is called and uses the COM+ methods) and a second payment calls the same method, the error is thrown back to my WCF service, and the line "transaction.Complete();" is not reached, but there is no rollback in database changes. How do
I make it rollback those changes ? If maybe my code is not the best for the situation, please comment as well
Thanks,
推荐答案
您好,FMoutinho,
Hi FMoutinho,
谢谢您在这里发布.
由于您的问题与WCF更相关,因此我将其移至 WCF论坛以获得适当的支持.
Since your problem is more related to WCF, I will move it to WCF Forum for suitable support.
Visual C#论坛讨论并询问有关C#编程语言,IDE,库,示例, 和工具.
The Visual C# forum discuss and ask questions about the C# programming language, IDE, libraries, samples, and tools.
温迪
这篇关于我无法使COM +使用WCF服务的同一事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!