简体   繁体   English

WCF服务:丢弃的连接处理

[英]WCF Services: Dropped connection handling

Have a WCF Service being called to update records in the database. 有一个WCF服务被调用来更新数据库中的记录。 If the connection is broken, the service will continue to process the data, but the client won't know of the results. 如果连接断开,服务将继续处理数据,但客户端将不知道结果。 IE the processing could have succeeded or failed; IE处理可能成功还是失败; the client doesn't know if it should resend the data. 客户端不知道是否应该重新发送数据。

Typical example would be a bank deposit. 典型的例子是银行存款。 An ATM takes a deposit and makes a WCF call to update the customer's account. ATM机取款并进行WCF呼叫以更新客户的帐户。 The connection is dropped, leaving the ATM uncertain as to whether the deposit was processed or not. 连接被断开,使ATM无法确定是否处理了存款。 If it wasn't, and the ATM doesn't resend, the customer doesn't have the money in his account. 如果不是,并且ATM没有重新发送,则客户的帐户中没有钱。 If the ATM resends, but the deposit was processed, he'll have two deposits. 如果自动提款机重新发送,但存款已处理,则他将有两次存款。

Enabling transactions on the WCF Service call seems the thing to do, but can they handle a dropped connection? 在WCF服务调用上启用事务似乎很重要,但是它们可以处理断开的连接吗? IE the client can roll back the transaction if it loses connection to the server, but how would the server know about the rollback if the client isn't connected? IE,如果客户端失去与服务器的连接,则客户端可以回滚事务,但是如果客户端未连接,服务器如何知道回滚?

It seems that any way you look at it, there is a possible issue for serious catastrophic failure. 从任何角度看,严重的灾难性故障都可能存在问题。

Assuming that you are using async client calls and/or the ammount of processing being done on the service side is relatively large. 假设您正在使用异步客户端调用和/或在服务端进行的处理量相对较大。 If in the span of the ammount of time, the connection to the service from the client is severed, there is no way for the client to know what state the service was last left in. If it was mid-transaction, the service side transaction will be cancled automatically... if it was post-transaction then your work is done... but in both situations the client will "never know". 如果在这段时间内,客户端断开了与服务的连接,则客户端无法知道服务最后保留的状态。如果是事务中,则表示服务端事务将自动取消...如果是在交易后,那么您的工作就完成了...但是在两种情况下,客户都将“永远不知道”。

Theoretically... (and don't quote me on this, but it SOUNDS like a logical scenario) if an ATM loses connection in the process of doing a deposit... I believe (and like I said don't quote me on this) that the ATM itself keeps a list of transaction in memory so that in a situation where a transaction fails, once the connection is re-established it can check itself and verify if the transaction was actually completed. 从理论上讲...(不要在此引用我的名字,但听起来像是合乎逻辑的情况),如果ATM在存款过程中失去连接...我相信(而且就像我说过的,不要在上面引用我的名字)这样),ATM本身会在内存中保存一个事务列表,以便在事务失败的情况下,一旦重新建立连接,它就可以检查自身并验证事务是否真正完成。 (If it in reality doesn't do this... I would be a bit concerned personally). (如果实际上不这样做,我个人会有点担心)。

To make a long story short... I believe the only thing you can do in this scenario is to have the client side keep some sort of checksum which would match with the service side so that if a connection failure occurred, when the connection was re-established, it would be able to check against the service to see if the transaction did in fact complete or not. 长话短说...我相信在这种情况下,您唯一可以做的就是让客户端保留某种与服务端相匹配的校验和,以便在发生连接失败时,重新建立后,它将能够对照服务检查交易是否确实完成。

我将使用BizTalk之类的EAI提供程序来协调WCF服务,并为服务公开的每个操作设置补偿操作,以便在发生故障时可以执行回滚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM