kay*_*yak 3 .net c# wcf soa .net-3.5
在WCF 4.0中,如何将3个不同的服务操作作为单个事务提交?(在SOA中提交)
我有3个不同的WCF服务,如下所示,每个服务方法调用DB操作
service1.CreateEmployee();
service2.SendSetupRequestForEmployee();
service3.GiveOfficePermissionToEmployee();
Run Code Online (Sandbox Code Playgroud)
即使一个操作失败,整个事情也应该回滚......任何帮助都会受到赞赏.
简短的回答:在a下进行服务呼叫TransactionScope
,并确保将呼叫本身设置为在事务下运行.
TLDR 在这里阅读这篇文章.
基本上,您需要装饰您的Operation Contract方法:
[TransactionFlow(TransactionFlowOption.Allowed)]
void MyWcfServiceCall() {...}
Run Code Online (Sandbox Code Playgroud)
并且服务方法调用自身:
[OperationBehavior(TransactionScopeRequired = true)]
void MyWcfServiceCall() {...}
Run Code Online (Sandbox Code Playgroud)
并打电话给 TransactionScope
using (TransactionScope tx = new TransactionScope(TransactionScopeOption.RequiresNew)) {
myServiceClient.MyWcfServiceCall();
myOtherServiceClient.MyOtherWcfServiceCall();
tx.Complete();
}
Run Code Online (Sandbox Code Playgroud)
在配置文件中绑定,将transactionFlow设置为true
:
<bindings>
<wsHttpBinding>
<binding name="MyServiceBinding" transactionFlow="true" ... />
</wsHttpBinding>
</bindings>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
318 次 |
最近记录: |