WCF 4.0 SOA 提交作为事务

发布于 2024-10-01 14:07:59 字数 277 浏览 1 评论 0原文

在 WCF 4.0 中,如何将 3 个不同的服务操作作为单个事务提交? (在 SOA 中提交)

我有 3 个不同的 WCF 服务,如下所示,每个服务方法都会调用数据库操作

service1.CreateEmployee();

service2.SendSetupRequestForEmployee();

service3.GiveOfficePermissionToEmployee();

即使一个操作失败,整个事情也应该回滚...任何帮助表示赞赏。

In WCF 4.0, How can I commit 3 different service operation as a single Transaction? (Commit in SOA)

I have 3 different WCF service like below, Each service method invokes DB operation

service1.CreateEmployee();

service2.SendSetupRequestForEmployee();

service3.GiveOfficePermissionToEmployee();

Even if one operation fails entire thing should be rolled back...any help appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

压抑⊿情绪 2024-10-08 14:07:59

简短的回答是:在 TransactionScope 下进行服务调用,并确保调用本身设置为在事务下运行。

TLDR请在此处阅读这篇文章。

基本上,您需要这样装饰您的操作合约方法:

[TransactionFlow(TransactionFlowOption.Allowed)]
void MyWcfServiceCall() {...}

服务方法调用自身:

[OperationBehavior(TransactionScopeRequired = true)]
void MyWcfServiceCall() {...}

TransactionScope 下调用

using (TransactionScope tx = new TransactionScope(TransactionScopeOption.RequiresNew)) {
    myServiceClient.MyWcfServiceCall();
    myOtherServiceClient.MyOtherWcfServiceCall();
    tx.Complete();
}

并在配置文件中的 绑定,将 transactionFlow 设置为 true:

<bindings>
    <wsHttpBinding>
        <binding name="MyServiceBinding" transactionFlow="true" ... />
    </wsHttpBinding>
</bindings>

The short answer: Make your service calls under a TransactionScope, and make sure the calls themselves are set up to run under transactions.

TLDR read this article here.

Basically, you need to decorate your Operation Contract method as such:

[TransactionFlow(TransactionFlowOption.Allowed)]
void MyWcfServiceCall() {...}

and the service method call itself with:

[OperationBehavior(TransactionScopeRequired = true)]
void MyWcfServiceCall() {...}

and call under a TransactionScope

using (TransactionScope tx = new TransactionScope(TransactionScopeOption.RequiresNew)) {
    myServiceClient.MyWcfServiceCall();
    myOtherServiceClient.MyOtherWcfServiceCall();
    tx.Complete();
}

in your config file for the bindings, set transactionFlow to true:

<bindings>
    <wsHttpBinding>
        <binding name="MyServiceBinding" transactionFlow="true" ... />
    </wsHttpBinding>
</bindings>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文