简体   繁体   English

通知WCF服务取消当前执行的操作并返回剩余数据。

[英]Notify WCF Service to cancel the currently executing operation and return remaining data.

I have this client application that sends thousands of items for deletion to my wcf service. 我有这个客户端应用程序,它向我的wcf服务发送了数千个要删除的项目。 Since the data is sent in bulk, even if I cancel the operation (with progress bar), all items are deleted. 由于数据是批量发送的,即使取消操作(带有进度条),所有项目也会被删除。 The behavior I want is to be able to cancel the delete operation in the service and retrieve items that are not deleted. 我想要的行为是能够取消服务中的删除操作并检索未删除的项目。 Thank you. 谢谢。

What InstanceContextMode are you using? 您正在使用什么InstanceContextMode?

What you want to do will work with InstanceContextMode Singleton or Session, but not PerCall. 您要执行的操作将与InstanceContextMode Singleton或Session一起使用,但不适用于PerCall。

I suppose that your method that initiates the delete in bulk operation is OneWay. 我想您启动批量删除操作的方法是OneWay。

Create a bool field (initially false) in your service. 在您的服务中创建一个布尔字段(最初为false)。 Your loop that deletes records one by one checks that flag and stops if the flag is true. 您删除记录的循环将一一检查该标志,如果该标志为true,则停止。

Create another method in your service that sets that field to true. 在服务中创建另一个方法,将该字段设置为true。 Call the new method from your website when you press the "Cancel Delete" button. 当您按下“取消删除”按钮时,从您的网站调用新方法。 The looop for deleting records will break. 删除记录的循环将中断。

Returning the records that were not deleted will be a bit tricky. 返回未删除的记录会有些棘手。 Your list of records to delete will need to be a memebr of the service class also, so that the method that stops the delete has access to the list also. 您要删除的记录列表也必须是服务类的成员,以便停止删除的方法也可以访问该列表。 The method that deletes from the db shoulkd also remove the records from the list one by one so you can keep track of remaining items. 从数据库删除的方法也应从列表中一一删除记录,以便您可以跟踪其余项。

You could return immediately in the second method the list, but thia does not guarantee accurate results. 您可以在第二种方法中立即返回列表,但这并不保证准确的结果。 What I would do is do a wait of 200 ms before returning. 我要做的是在返回之前先等待200毫秒。 That way you know that the item removed from the list is really deleted in the db. 这样,您就知道从列表中删除的项目实际上已在数据库中删除。

Hope this is clear... 希望这很清楚...

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

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