.net – Single WCF Service to multiple client connections


I have developed a VB.NET WCF service that recives and sends back data. When the first client connects it starts the data output that continues also if the client is closed. If a new client connects then a new object is created and the data output starts at the begninning and continues in parallel with the old instance. Is there a way to read the same service object from multiple clients?

The service is self-hosted.

UPDATE: I solved the problem adding the following bit of code to the service class:


To use the ServiceHost overload that takes in the SingletonInstance, the service must be tagged with the appropriate ServiceBehaviours.

Best Solution

I talk about the options here:


First, you have InstanceContextMode which can be Single, PerCall, or PerSession. This controls how new instances of your service class are created.

In addition to this, the throttling and concurrency settings are important to look at, since setting instance context mode to something like single without changing the concurrency mode to multiple could have seriously negative consequences. Take a look at the post for a more detailed discussion.

Related Question