[Mono-dev] WCF: InstanceContextMode.PerSession

Karsten Fourmont fourmont at gmx.de
Sun Jan 9 09:15:04 EST 2011


Hi Atsushi,

 > One (slightly) better approach is to avoid configuration. It is
 > extraneous stack to the actual code implementation for us and often
 > left not-implemented.
OK, understood.

After changing to configuration in code and tinkering some more I came 
to the next hurdle: session instance handling.

Currently Mono creates a new instance of the service object for every 
method call. That's not what's usually desired for sessions.

from http://msdn.microsoft.com/en-us/library/ms733040.aspx:
<quote>
If you use the default instancing behavior in WCF, all calls between a 
WCF client object are handled by the same service instance. Therefore, 
at the application level, you can think of a session as enabling 
application behavior similar to local call behavior. For example, when 
you create a local object:
  - A constructor is called.
  - All subsequent calls made to the WCF client object reference are 
processed by the same object instance.
  - A destructor is called when the object reference is destroyed.
</quote>

As usual the details are even more complex as WCF is highly 
customizable. A helpful read is
http://www.pluralsight-training.net/community/blogs/aaron/archive/2006/02/27/19253.aspx

But it comes down to this: if you set
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
on a service, all client calls in one session should go to the same 
service instance and the service instance should be disposed when the 
session ends.

I created a Nunit Test (passes on .net fails on mono 2.8.1) for this and 
filed bug https://bugzilla.novell.com/show_bug.cgi?id=663278

If there's anything I can do to help, just let me know.

Cheers,
  Karsten




More information about the Mono-devel-list mailing list