Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Indigo

Vista - WCF - ServiceBehavior InstanceContextMode?

 
 
Old 08-10-2007   #1 (permalink)
Peter K


 
 

WCF - ServiceBehavior InstanceContextMode?

Hi

I have a few basic questions regarding WCF.

In a WCF service, if no [ServiceBehavior] attribute is supplied, does that
mean that the service InstanceContextMode is "per call" or "per session"?

At this location, it states that "per call" is the default:
http://msdn.microsoft.com/msdnmag/is...s/default.aspx

This location states the default is "per session":
http://wcf.netfx3.com/content/Breaki...2andJuneCTP.as
px

So I would like to know what the default actually is, and I would also like
some help understanding what they mean for my clients and service :-)

Does "per call" mean that a new instance of the ServiceContract class
is instantiated for every call to each and every method in the
ServiceContract class? This would mean (I assume) that every call is
entirely seperate from every other call - the service has no "memory" of
previous calls - and I would need to instantiate any "helper classes", db-
connections etc on every single call.

Does "per session" mean that a new instance of the ServiceContract class is
created for each client. But only once for each client, and the instance
persists between calls? Thus, state is maintained in the service between
each client's calls. So if client A calls a method in the service, and the
service initialises some static variables, those variables would still be
set when client A next calls the service? But do client A and client B
share anything in the service (fx static variables) or is every client
completely isolated from each other?


Furthermore, how does SessionMode.Allowed affect the two
InstanceContextModes?


Thanks for any help,
Peter

My System SpecsSystem Spec
Old 08-13-2007   #2 (permalink)
ronscottlangham@yahoo.com


 
 

Re: WCF - ServiceBehavior InstanceContextMode?

On Aug 10, 2:03 am, Peter K <xdz...@hotmail.com> wrote:
> Hi
>
> I have a few basic questions regarding WCF.
>
> In a WCF service, if no [ServiceBehavior] attribute is supplied, does that
> mean that the service InstanceContextMode is "per call" or "per session"?
>
> At this location, it states that "per call" is the default:http://msdn.microsoft.com/msdnmag/is...ntials/default....
>
> This location states the default is "per session":http://wcf.netfx3.com/content/Breaki...taBeta2andJune...
> px
>
> So I would like to know what the default actually is, and I would also like
> some help understanding what they mean for my clients and service :-)
>
> Does "per call" mean that a new instance of the ServiceContract class
> is instantiated for every call to each and every method in the
> ServiceContract class? This would mean (I assume) that every call is
> entirely seperate from every other call - the service has no "memory" of
> previous calls - and I would need to instantiate any "helper classes", db-
> connections etc on every single call.
>
> Does "per session" mean that a new instance of the ServiceContract class is
> created for each client. But only once for each client, and the instance
> persists between calls? Thus, state is maintained in the service between
> each client's calls. So if client A calls a method in the service, and the
> service initialises some static variables, those variables would still be
> set when client A next calls the service? But do client A and client B
> share anything in the service (fx static variables) or is every client
> completely isolated from each other?
>
> Furthermore, how does SessionMode.Allowed affect the two
> InstanceContextModes?
>
> Thanks for any help,
> Peter


Not sure what the default is, but if you intend to use, best to
specify it explicitly using InstanceContextMode.

Correct on your description of the PerCall.

Mostly correct on your description of PerSession. The data shared is
not in static variables, but in instance variables of the class that
implements the service contract. You can define variables in the
class and their values will be the same between calls since a unique
class instance is created for each client. There is not sharing of
data between different clients.

SessionMode.IsAllowed specifies that if the binding supports sessions,
then a session will be created. If the binding does not support
sessions, then sessions will not be used and no error will occur. If
you are designing a class that is designed to work only under sessions
and would fail otherwise, advise that you set the SessionMode to
Required. This way you will know immediately that sessions are not
working, otherwise, your service may initially work but then start to
misb ehave since data is not maintained between calls.

See link below, may help some..

http://msdn2.microsoft.com/en-us/lib...ssionmode.aspx

Also, take a look at IsInitiating and IsTerminating attributes, and
the ReleaseInstanceMode attribute, this provide you some more control
of the lifetime of the instance created for the client session.

Ron

My System SpecsSystem Spec
 

Thread Tools



Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46