As I understand from this article:
Single: This will help us to share the data globally. We can create only one instance and the same instance will be reused on the subsequent calls. Same like Per Session this will work with all bindings except basicHttpBinding.
InstanceContextMode.Single not available for basicHttpBinding.
But according to this answer it works.
This article adds confusion.
I'd like to get clear answer and explanation.
InstanceContextMode.Single will force the WCF engine to create a single instance of your service class through the lifetime of your service. This means that all requests will share the same instance rather than creating one per request.
This is entirely possible with basicHttpBinding.
Here is an example using basicHttpBinding and InstanceContextMode.Single:
First my Service class which has private field that keeps the count of requests:
Now my Service Contract:
Lastly here is my config file with a single binding using basicHttpBinding:
Now using the default WCF Test Client that comes with Visual Studio here are the results:
First call the count is 1:
Second call the count is 2:
A few clicks later the count is still being preserved:
I am not sure why some articles state that InstanceContextMode.Single is not supported by basicHttpBinding. It is obviously not true.
I use InstanceContextMode.Single combined with ConcurrencyMode.Multiple for high throughput services all the time.
It also has the advantage that you can keep some "state" during the lifetime of the service that can be shared across all requests. For example I keep commonly used data in private fields to avoid loading it from the database on every request etc.