[Mono-dev] WCF: InstanceContextMode.PerSession

Karsten Fourmont fourmont at gmx.de
Sun Jan 9 10:03:57 EST 2011


sigh: it seems no matter how long I wait before making a post to get the 
details right, still every time something comes up minutes after I hit 
the "send" button.

So here's a small addition:
It doesn't seem very well defined in the WCF documentation if an when 
Dispose should be called on a service instance. Service classes don't 
have to be IDisposable. But if they are, .NET invokes Dispose and I 
think mono should do the same. However exactly "when" this dispose is 
supposed to happen is not perfectly clear:
http://msdn.microsoft.com/en-us/library/ms733040.aspx states:
"In the default case, WCF recycles the service object and its context 
after the session with which the service was associated is closed."
So Dispose doesn't have to be called on session termination, but 
(maybe?) on service channel termination on the server side. Whatever.

The service instance just has to be able to find out when it should free 
the session's resources once the session is closed either by the client 
or by the server (like due to an inactivity timeout).

Atsushi, I definitely don't envy you (or any of the mono team) for 
having to implement something which is not properly specified. Only 
Perl's "the implementation is the specification" seems worse ;-)
Great work!

Cheers,
  Karsten

Karsten Fourmont schrieb:
> 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
>
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list



More information about the Mono-devel-list mailing list