WCF Tutorial
Lección 58 de 236 · Part 43 Single concurrency mode in WCF · Bases de datos
Part 43 Single concurrency mode in WCF
Link for all dot net and sql server video tutorial playlists
http://www.youtube.com/user/kudvenkat/playlists
Link for code samples used in the demo
http://csharp-video-tutorials.blogspot.com/2014/03/part-43-single-concurrency-mode-in-wcf_31.html
In this video we will discuss the Single concurrency mode in WCF with examples.
To understand concurrency better, we need to understand
1. Instance Context Modes in WCF – Discussed in Parts 36 to 42 in WCF video series
2. Multithreading concepts – Discussed in Parts 86 to 97 in C# video series
In addition we also need to understand the term throughput. Throughput is the amount of work done in a specified amount of time.
Multiple threads executing the application code simultaneously is called as concurrency. In general with concurrency we get better throughput. However, concurrency issues can occur when multiple threads access the same resource. In WCF, Service Instance is a shared resource.
The default concurrency mode in WCF is Single. This means only a single thread can access the service instance at any given point in time. While a request is being processed by the service instance, an exclusive lock is acquired and all the other threads will have to wait until the current request completes and the lock is released. Upon relasing the lock, next thread in the queue can access the service instance.
ConcurrencyMode parameter of the ServiceBehavior attribute controls the concurrency setting
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single)]
ConcurrencyMode can be
Single
Reentrant
Multiple
In this video we will discuss Single concurrency mode with the 3 different instance context modes available in WCF
PerCall – each request is served by a new instance of the service
PerSession – all requests from a single proxy instance are served by the same service instance
Single – all requests are served by the same instance of the service
Test the WCF service using the Windows Client application while changing the binding and Instance Context Mode.
Whether a WCF service handles client requests concurrently or not depends on 3 things
1. Service Instance Context Mode
2. Service Concurrency Mode and
3. Whether if the binding supports session or not