O'Reilly logo

Microsoft Windows Communication Foundation 4.0 Cookbook for Developing SOA Applications by Steven Cheng

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hosting a singleton instance service

Singleton is a very popular design pattern used in application development. And for WCF services, sometimes it is useful to build a singleton-style service that will only use one instance object to serve all the operation calls from the client. This recipe will show you how to make a WCF service in singleton style.

How to do it...

In order to make a WCF service create a single instance of the Service type, we can apply InstanceContextMode through ServiceBehaviorAttribute on the service implementation type of our service. The following code snippet shows the sample service class, which has ServiceBehaviorAttribute applied and the InstanceContextMode property set to Single.

[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)] ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required