6

I am exposing a WCF service through a basicHttpBinding that executes several operations on a database.

I want to guarantee that if the client does not receive the reply the database operations are rolled back (without any transaction flow through WCF). E.g. the client calls the "DoX" method which executes on the server but before it is finished the client crashes. The database operations should then be rolled back as soon as the reply can not be send to the client.

Is there any way to do that? Will the [OperationBehavior(TransactionScopeRequired=true)] attribute work in such a manner? Is there a possibility to handle communication errors on the server side?

Update 1: It seems [OperationBehavior(TransactionScopeRequired=true)] commits the transaction before the reply is send to the client and thus can not be used to perform a rollback if the client does not receive the reply.

Update 2: To state it clearly again, I do not have the need for the transaction to interact in any way with the client side. The client should neither know of the transaction, have the ability to cancel or commit it, nor should any transaction flow through the binding. The only place I want the transaction to rollback is on the server side if the transport channel can not deliver the message to the receiving client. With the case of TCP/IP this information should be readily available to the server. (No ACK of the TCP packet send back to the client)

So a hypothetical execution flow on the server side (notice the lack of client side) should be:

Receive client request

Start transaction

Execute all logic inside the service operation

Send reply back to client

if (reply.failedToReceive) { transaction.Rollback() } // due to a failing TCP/IP transmission
4

1 に答える 1

1

この質問に対する簡単な答えはありません。WS-* に実装されているが、基本的な SOAP を使用して実行される動作を求めています。本当に wsHttpBinding に切り替えたり、@ Trevor Pilley が提案したように duplex を使用したりできない場合の唯一の選択肢は、基本的な SOAP に基づいた独自のカスタム プロトコルで WS-Transaction の動作を模倣することだと思います。

完全な WS-Transaction 仕様よりもいくらか単純化できるはずです。

  • おそらく、単一のサービスでトランザクションをサポートするだけで済みます。複数の独立したサービスで分散トランザクションを実行する必要はありません。
  • 短いトランザクション ( WS-AtomicTransaction ) と長時間実行されるトランザクション ( WS-BusinessActivity ) の両方をサポートする必要はありません。
  • あらゆる種類の拡張モデル ( WS-Coordination )をサポートする必要はありません。
  • プロトコルの動作をクライアントとサービスに直接コーディングするため、プロトコルを記述する検出/メタデータ モデル (WSDL など) を実装する必要はありません。

ただし、おそらく WS-Coordination と WS-AtomicTransaction の両方の要素が必要になるでしょう。これは決して単純な作業ではなく、ロールバックが発生しないか、または (同様に悪いことに) データベース全体に長時間のロックがかかることでサービスのパフォーマンスが損なわれる原因となる微妙な何かを見逃すのは簡単です。クラッシュしたクライアント。

私が言うように、これは複雑な動作であり、既成の標準化されたプロトコルを使用できない場合、簡単な答えはありません.

于 2012-02-21T20:16:03.507 に答える