Gracefully terminate WCF Service - complete all open sessions and restrict new sessions

落爺英雄遲暮 提交于 2019-12-21 04:52:36

问题


I have a WCF Service that I have written, which is hosted within a Windows service. It is operating in PerSession mode. The service permits clients to open files, make changes to files and close files remotely through the service. So far all works very smoothly.

When the Windows service is stopped, I would like to be able have the WCF Service not accept any new sessions and yet allow already connected clients to complete their current sessions and work (within a reasonable period/timeout).

What would be the best way to accomplish this?


回答1:


Basically, calling ServiceHost.Close() will accomplish this - it will let all currently running request run to completion, but new request are being rejected will the orderly shutdown is in progress.

There's a "CloseTimeout" setting on your binding that you configured for your service - that controls how long the WCF runtime will allow running requests to take until they've properly shut down. If that timeout happens, the still running requests will be killed.

The ServiceHost.Abort() method on the other hand is the digital equivalent of a sledgehammer - all running requests are terminated at once, and the host is shut down.

ON the client side, you have the same .Close() and .Abort() methods on your client proxy which behave the same way.



来源:https://stackoverflow.com/questions/1664935/gracefully-terminate-wcf-service-complete-all-open-sessions-and-restrict-new-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!