Resource cleanup when WCF Sessionful service suddenly shuts down

I have a WCF session service that starts a process and opens a named pipe for this process when the IsInitiating operation is called. When the IsTerminating operation is called, the service sends a message down the channel to inform the process at the other end that it might shut down. Unfortunately, if the client does not disconnect gracefully (by invoking the IsTerminating operation), then the message is never sent to the channel, and the other process never exits.

I tried to make my service an IDisposable implementation (in the hope that when the session ends on the server, it will call my Dispose method), but this does not seem to work.

Is there any way I can call the server-side code when the client disconnected (even if I need to wait for the Timeout to be inactive)?

+3
source share
1 answer

The idea with IDisposable should work. Set the instance context mode, for example:

From MSDN: http://msdn.microsoft.com/en-us/magazine/cc163590.aspx

[ServiceBehavior (InstanceContextMode = InstanceContextMode.PerSession)] class MyService: IMyContract {...}

, -, , . IDisposable, Dispose. 4 , . , .

0

Source: https://habr.com/ru/post/1710162/


All Articles