I have a WCF service that has been giving me this error under load conditions (and I can\'t seem to recreate the error otherwise). We\'ve been trying to find a way around it for
This error can also be caused by mixing using
clauses with asynchronous calls to WCF services.
For example:
using (ServiceClient proxy = new ServiceClient(proxyName)) {
proxy.Open();
return proxy.FunctionCallAsync(parameters); //Return type being Task
}
This will trigger a race condition between how fast can it dispose of proxy
versus how fast the asynchronous Task
can be completed. Longer the task takes the more likely it will be to end up in a Faulted state and the Result containing a System.ServiceModel.CommunicationException.
This can be fixed by removing the using clause:
ServiceClient proxy = new ServiceClient(proxyName))
proxy.Open();
return proxy.FunctionCallAsync(parameters); //Return type being Task
Note that proxy
should be persisted too so that once the asynchronous call is completed that a proxy.Close()
can be done.