开发者

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

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 se开发者_C百科ssions 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜