简体   繁体   中英

Communication WCF constant connection

当将WCF用于2台计算机通过网络进行通信时,我正在远程服务器上执行一种方法,因此该操作可能花费的时间未知,它可能需要1秒钟到一天甚至更长的时间,因此我想设置((IClientChannel)pipeProxy).OperationTimeout属性设置为较高的值,但这是((IClientChannel)pipeProxy).OperationTimeout的方法还是这是一种肮脏的编程方式,因为连接始终处于活动状态(所有连接均处于相对稳定的lan网络上)。

I wouldn't do it like that. Such a long timeout is likely to cause issues.

I would split the operation into two: One call from client to server which starts the operation, and then a callback from the server to the client to say that it's finished. The callback would of course include any result information (success, failure etc).

For something which takes such a long time, you might also want to introduce a "keep alive" mechanism where the client periodically calls the server to check that it is still responding.

If you have a very long timeout, it makes it hard to know if something has actually gone wrong. But if you split the operation into two, it makes it impossible to know if something has gone wrong unless you poll occasionally with a keep-alive (or more accurately, "are you alive?") style message.

Alternatively, you could have the server call back occasionally with a progress message, but that's a bit harder to manage than having the client polling the server occasionally (because the client would have to track the last time the server called it back to determine if the server had stopped responding).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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