views:

157

answers:

1

I have a sessionful WCF service that spawns a process and opens a named pipe to this process when the IsInitiating operation is called. When the IsTerminating operation is called, the service sends a message down the pipe to inform the process on the other end that it can shut-down. Unfortunately, if the client doesn't disconnect gracefully (by calling the IsTerminating operation), then the message is never sent down to the pipe and the other process never exits.

I tried making my service implement IDisposable (in the hope that when the session times out on the server it will call my Dispose method), but this doesn't seem to work.

Is there any way that I can call some code on the server side when the client has disconnected (even if I have to wait for an inactivityTimeout)?

A: 

The idea with IDisposable should work. Set your instance context mode like:

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

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

The session typically terminates when the client closes the proxy, which notifies the service that the session has ended. If the service supports IDisposable, then the Dispose method will be called. Figure 4 shows a contract and service configured to use a private session and their client. As you can see from the output, the client got a dedicated instance.

Alex