3

I have a WCF Service that is transferring large files.

Currently I'm using Singleton service with list of instances from my class to hold the state and to response to the client requests for transfer progress and so on.

The instanced class itself handles new threads for each transfer when needed.

Clients who add transfer requests and request progress can disconnect meanwhile and reconnect at random time for the requests.

Also several different clients may want to request progress of all transfers that are going on.

Everything is working great as it is, but I'm sure there is better way of doing this?

Storing state somehow in SQL? Storing state as I'm currently doing and somehow reconnecting to the same instance? How to get data from all instances then?

I hope you understood my rather long question :)

4

1 回答 1

2

如果你的 WCF 服务只有一个实例,你的解决方案会很好用。

当您使用负载平衡实例化多个实例时,该方法将不起作用。
在这种情况下,您需要保持状态是所有实例共有的某个地方。它可以是 SQL、状态服务器、另一个可以保持状态的 WCF 服务等。

更新
您需要为每个文件传输任务生成 id。然后 Singletone 可以将 id 与确实传输的实例相关联(我们称之为 Executor)。
当客户端想要获得进度或取消传输时,它会请求 Singletone 并提供任务 ID。
Singletone 应该使用 task id 来解析实际的 Executor 并将客户端的请求转发给正确的 Executor。

因此,您将能够根据需要实例化尽可能多的 Executor。客户不应该担心究竟是哪个 Executor 处理文件。客户应该知道的一切都是任务ID。

于 2012-11-22T20:56:02.763 回答