Alex Rivera | Logout

Is WCF ClientBase thread safe?

Asked 2011-01-07T12:18:28.810
34

I have implemented ClientBase to use WCF to connect to a service. I'm then calling a method on the channel to communicate with the service.

base.Channel.CalculateSomething();

Is this call thread safe or should I lock around it when running multiple threads?

Thanks

Edit
Report

1 Answer

15

Yes, it is thread-safe. However, you should know that WCF will automatically serialize the execution of CalculateSomething when it is called from more than one thread using the same ClientBase instance. So if you were expecting CalculateSomething to run concurrently then you will have to rethink your design. Take a look at this answer for one approach to creating an asynchronous API for the CalculateSomething method.

answered 2011-06-08T15:24:09.307

Your Answer