我已经实现了这样的WCF服务:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Single, UseSynchronizationContext=false)]
public sealed class SynchronizationService : ISynchronizationService, IDisposable
{
private MemoryStream objectStream;
...
}
Run Code Online (Sandbox Code Playgroud)
ISyncrhonizationService具有[ServiceContract(SessionMode = SessionMode.Required)].
如果客户端正确通信并最终使用[IsTerminating = true]调用方法,那么我可以很好地处理objectStream变量.如果由于某种原因服务和客户端之间的通信中断,我想自己从服务端清理objectStream变量,这就是我想实现IDisposable接口的原因.但是看一下MSDN文档(http://msdn.microsoft.com/en-us/library/system.idisposable.aspx)我对此有点怀疑,因为根据文档:
// Dispose(bool disposing) executes in two distinct scenarios.
// If disposing equals true, the method has been called directly
// or indirectly by a user's code. Managed and unmanaged resources
// can be disposed.
// If disposing equals false, the method has been called by the
// runtime from inside the …Run Code Online (Sandbox Code Playgroud) wcf ×1