Incorrect: These options would cause a single instance of the service object to be created for all requests. The concurrency mode of Multiple means that more than one simultaneous request is possible. With multiple requests, the possibility of concurrency issues associated with updating the hitCounter variable exists.
Correct: The use of a concurrency mode of Single ensures that only one request at a time can be processed. Even though more than one session could be active, the fact that the hitCounter variable is an instance variable means that it cannot be updated by more than one thread at a time.
Incorrect: Even though the InstanceContextMode is set to PerSession, more than one request, even from the same session, can occur. This means that two requests can be processed in the same instance, which, in the case of the class, means that concurrency problems can occur.
Correct: The Single concurrency mode ensures that only one request is processed at a time, and the Single instance context mode means that only one instance is ever created.
A:
Correct Answer: D
Incorrect: These options would cause a single instance of the service object to be created for all requests. The concurrency mode of Multiple means that more than one simultaneous request is possible and, with multiple requests, the possibility of concurrency issues associated with updating the hitCounter variable exists.
Incorrect: Although a concurrency mode of Single ensures that each service object can process only one request at a time, this is not sufficient when a shared or static variable is being used. The fact that the instance context mode is PerSession means that multiple service objects can be instantiated, each of which could update hitCounter. This introduces the possibility of concurrency problems.
Incorrect: Having a PerSession instance context means multiple service objects, and a concurrency mode of Multiple means that simultaneous requests in each object are possible. Either one of these is sufficient to open up the possibility of concurrency issues.
Correct: The concurrency mode ensures that only one request is processed at a time, and the instance context mode means that only one instance is ever created. This combination is required for static or shared variables to be safe from concurrency violations.
A.23.2. Lesson 2
A:
Correct Answer: C
Incorrect: Updating a SQL Server database (or any database) does not require any thread affinity.
Incorrect: Calls to external Web services do not require thread affinity to be involved.
Correct: To interact with the user interface on the Windows form, you must process the requests on the user interface thread. This requires the synchronization context to be used.
Incorrect: Using threads in the thread pool does not innately require a synchronization context to be created.
A:
Correct Answer: D
Incorrect: Deriving the service class from the SynchronizationContext class means that it could be used as a synchronization context, but it does not mean that requests processed by that service will use that context.
Incorrect: Setting UseSynchronizationContext to true means that, if the host has an active synchronization context, the incoming requests will use it. It does not cause the host to have a synchronization context.
Incorrect: Although the IContextBehavior interface associates a custom context with a request, having the service class implement it doesn’t activate the necessary mechanism.
Correct: The attribute that implements IContextBehavior is required to attach the custom synchronization object to an incoming request.
You are currently reading a PREVIEW of this book.
Get instant access to over
$1 million worth of books and videos.