What is the default behavior for instancing service objects in WCF?
I've been preparing for MS 70-513 exam and with the Self-paced training kit content cd there are some practice tests.
The following is one question of those tests which I kindly ask someone to explain. The correctly marked answer is A, however I don't understand why D isn't the correct one.
Question:
What is the default behavior for instancing service objects in WCF?
A - Each instance is associated with one user-defined service object.
B - Each instance handles all requests for the lifetime of the requesting application.
C - A new instance is created for 开发者_如何学编程each client request.
D - A new instance is created for each new client session.
Thakns in advance, Bruno
I got an answer from msdn forums, I guess I'm convinced with it.
http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/2e35729f-603a-4a52-a3b7-920c9f3a8100/
Quoting the answer:
This is a tricky one - I assume that the reason D is not true is that not every client creates a session. For example basicHttpBinding does not support sessions. So if you don't always have a session - D is not always true. However, A is always true (unless you create your own custom behavior) because every InstanceContext object wraps a single user-defined service object (an object created according to your service type)
It's PerSession
http://msdn.microsoft.com/en-us/library/ms733040.aspx
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. Sessions enable a similar behavior between clients and services as long as the default service instance behavior is used. If a service contract requires or supports sessions, one or more contract operations can be marked as initiating or terminating a session by setting the IsInitiating and IsTerminating properties.
I would think D is correct as well, since InstanceContextMode
is set to PerSession
by default (link).
精彩评论