Multiple method call using same client instance to WCF service

670 Views Asked by At

My WPF application is calling the WCF service using a single client object. This is working fine when request is sent and response is coming immediately before next request.

When I am sending the first request and it is taking 3 minutes to complete the calculation task and return the result. In the meanwhile second request is sent from my WPF application (ping request is sent every 3 second). At this time, I am getting the following error and WPF application getting disconnected:

The server did not provide a meaningful reply: this might be caused by a contract mismatch, a prematured session shutdown or an internal server error

The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.

My service behavior is written as follows:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, IncludeExceptionDetailInFaults=true)]

I tried different combination and it is not working.

2

There are 2 best solutions below

1
AmirHossein Fathi On

If you do multiple concurrent calls from singel client you should set ConcurrencyMode to Multiple in addition to InstanceContextMode .. Note that if you set InstanceContextMode to Single, your service act as singleton, Then you should be aware of manipulating variables because it has reflection on other calls ..

0
nvoigt On

Your Ping request should not use the same Channel. It should open it's own channel. Ideally, every independent request should open it's own channel (alternatively, you could build a queuing system). But accessing the same channel from two different threads is not going to work.