Support us .Net Basics C# SQL ASP.NET Aarvi MVC Slides C# Programs Subscribe Download

Part 41 - Single instance context mode in WCF

Suggested Videos
Part 38 - PerSession instance context mode in WCF
Part 39 - PerSession WCF services
Part 40 - How to retrieve the sessionid in WCF service and in the client application



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.
singleton wcf service

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.

wcf tutorial

No comments:

Post a Comment

It would be great if you can help share these free resources