Learner
Learner

Reputation: 1542

Difference between WCF instance context modes : PerCall with MaxConcurrentCall set to 1 and Single instance service

I am just going through the possibilities of setting up the Instance Context mode of my service and there are two options for me.

1) Set the InstanceContext mode to single 2) Set the InstanceContext mode to PerCall and set the MaxConcurrentCalls to 1

With the first option, I'll have to apply the synchronize on the critical sections of the service but with the second option I don't have to do that.

Which option is preferable, please guide.

Upvotes: 0

Views: 974

Answers (1)

to StackOverflow
to StackOverflow

Reputation: 124696

With the first option, I'll have to apply the synchronize on the critical sections of the service but with the second option I don't have to do that.

If you set MaxConcurrentCalls to 1, you'll only ever have one active call, which will mean you don't need synchronization independend of InstanceContext.

If MaxConcurrentCalls is greater than 1, then:

  • With InstanceContext = Single, concurrent calls will share the same instance of your service class. You will therefore need synchronization when accessing instance members of the service class, as well as when accessing other shared resources (such as static properties).

  • With InstanceContext = PerCall, each call will get its own instance of the service class. You will therefore not need synchronization when accessing instance members of the service class. However you will need synchronization when accessing other shared resources (such as static properties).

As for which is preferable, it depends on whether your service class has per-call instance members.

Upvotes: 2

Related Questions