R – WCF Fails Under Load – MessageSecurityException

.netload-testingstress-testingwcf

I am load testing my website. The site calls to a WCF service running on the same box using clientCredentialType="Windows". Everything works until I reach a certain load (which is not even very high), then I get the following error:

System.ServiceModel.Security.MessageSecurityException:
The HTTP request was forbidden with
client authentication scheme
'Anonymous'. —->
System.Net.WebException: The remote
server returned an error: (403)
Forbidden.

Upon each call I create a channel:

var proxy = (IClientChannel)channelFactory.CreateChannel();

On success, I close:

proxy.Close();

On error, I abort:

proxy.Abort();

Any ideas what's going on? What I can do to handle loads better? What to look for?

Best Solution

Is your Service a Sessionful Service or do you not worry about keeping state between calls? If you don't have state, you may want to mark your service as a PerCall service. This will make sure that the service instance only exists when a client call is in progress.

Chapter 4 of Juval Lowy's excellent book "Programming WCF Services" 2nd Edition covers this topic.

The default is PerSession which may not be what you want.

Also, see this on MSDN: How To: Control Service Instancing

Related Question