axe
axe

Reputation: 2371

WCF client wrapper thread safety

I have WCF service

[ServiceBehavior(
    InstanceContextMode = InstanceContextMode.Single,
    ConcurrencyMode = ConcurrencyMode.Single,
    IncludeExceptionDetailInFaults = true)]
public class ClientAPI : IClientAPI { ... }

and .NET wrapper generated for this service when I add Service Reference.

Is that wrapper object thread safe? I mean can I call methods for this client object from different threads without synchronizing access to the object itself?

Upvotes: 1

Views: 815

Answers (1)

Alex
Alex

Reputation: 8937

Yes, with such model your service instance will be created once, and each query will be handled consequentially. But you have to check your service state, because if it fails, you have to create new instance. It would work like this, in a single thread enter image description here

Upvotes: 2

Related Questions