WCF Tutorial
Lección 122 de 236 · Part 41 Single instance context mode in WCF · Bases de datos
Part 41 Single instance context mode in WCF
Link for code samples used in the demo
http://csharp-video-tutorials.blogspot.com/2014/03/part-41-single-instance-context-mode-in_3.html
Link for all dot net and sql server video tutorial playlists
http://www.youtube.com/user/kudvenkat/playlists
In this video we will discuss, Single instance context mode in WCF with an example. This is continuation to Part 40. Please watch Part 40 before proceeding. We will be working with the same example we worked with in Part 40.
When the instance context mode for a wcf service is set to Single, only one instance of the wcf service class is created to handle all requests, from all clients. Let’s prove this with an example.
Set InstanceContextMode to Single, to create a single instance of a WCF service that handles all requests from all clients.
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class SimpleService : ISimpleService
Implications of creating a wcf service with Single instance context mode:
1. Since a single service instance is serving all client requests, state is maintained and shared not only between requests from the same client but also between different clients.
2. Concurrency is an issue
3. Throughput can be an issue. To fix the concurrency issue, we can configure the service to allow only a single thread to access the service instance. But the moment we do it throughput becomes an issue as other requests queue up and wait for the current thread to finish it’s work.