[Mono-dev] WCF: InstanceContextMode.PerSession

Atsushi Eno atsushieno at veritas-vos-liberabit.com
Tue Jan 11 01:03:01 EST 2011

Hello Karsten,

(2011/01/09 23:15), Karsten Fourmont wrote:
> 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.
Thanks for the investigation. Well, yes, session instance handling is 
far from perfect in mono yet (considering that it is server side feature).

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

I'm not fully remember about them, but it is probably rather that we 
lack checks session starts/ends in operation behaviors.
We have some basic session management support, but it is only limited to 
manage TCP channels (as no other supported bindings support sessions). 
And things were always either tied to Close() at client side, or session 
shutdown message from client at server side, so it basically worked.
On instancing, we take InsntaceContextMode into consideration, and AFAIR 
at least singleton worked. So, I less doubt lacking support for 
per-session instancing.

> 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.
Right, that's the expected behavior.

> 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.

It's been of great helps. Thanks a lot Karsten :) I'm back on this WCF 
work this January to complete things like this in the basic WCF stack. 
This issue is one of good starters.

Atsushi Eno

More information about the Mono-devel-list mailing list