I have a WsHttpBinding
request-reply service method that processes a transaction against a middle-tier service (which connects to the database) and returns a response message to the client with a transaction id.
I have a couple questions:
开发者_Python百科How can I detect when the client unexpected disconnects/faults before it receives the response? I noticed the the channel_faulted event never fires for
WsHttpBinding
.Assuming that #1 can be achieved, how can I get the original transaction id (that was in the outgoing response), in order to rollback/reverse that transaction that the client did not receive?
Any help is greatly appreciated. Thanks.
First, in general, the service should have little to no knowledge ever of its clients. The system should be designed in such a way that there's no tight coupling like this.
What this means for your scenario might be that you need to use Reliable messaging - something like NetTCPBinding
or WSHttpBinding
. If messages aren't received by the client, your server will know.
I suggest you take a look at chapter 7 in Juval Lowy's Programming WCF Services. Chapter 7 is all about transactions in WCF.
Transaction support in WCF allows your clients to propagate their transaction to a WCF service.
If you're using WCF transactions and a call back to a client fails for whatever reason, the transaction will abort (answer to your second question). In this way your service doesn't need to know anything about your client. WCF takes care of it for you.
Lowy recommends a combination of reliable messaging and transactionFlow. Something like:
<netTcpBinding>
<binding name="TransactionalTCP" transactionFlow="true">
<reliableSession enabled="true"/>
</binding>
</netTcpBinding>
精彩评论