views:

493

answers:

1

I am getting a "The message could not be processed..." error from a WCF client. Please help, it's killing me.

I have a test win app that goes through a for loop to kick of x number of asynchronous calls. Each asynchronous call instantiates its own instance of a WCF proxy and calls a WCF service using that proxy. If x is about 35 or less, all is well. If x > 40 or so, many of the calls complete just fine, but a handful return this:

System.ServiceModel.Security.MessageSecurityException: 
  An unsecured or incorrectly secured fault was received from the other party. 
  See the inner FaultException for the fault code and detail. ---> 
  System.ServiceModel.FaultException: The message could not be processed. 
  This is most likely because the action 'http://tempuri.org/IMyService/MakeRequest' 
  is incorrect or because the message contains an invalid or expired 
  security context token or because there is a mismatch between bindings. 
  The security context token would be invalid if the service aborted 
  the channel due to inactivity. To prevent the service from aborting 
  idle sessions prematurely increase the Receive timeout on the 
  service endpoint's binding.
  --- End of inner exception stack trace ---

Server stack trace: 
   at System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.ProcessReply(Message reply, TimeSpan timeout, SecurityProtocolCorrelationState correlationState)
   at System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at ...

I am using client-side and server-side certificates, with message security. I don't get why it runs OK only a certain number of times, then pukes. It also seems to throw the error on calls that are made closer to the end of the iteration. Also, this error occurs long before any of my timeouts would be reached, which are set on the client and server-side the same:

<binding name="WSHttpBinding_IMyService" 
         closeTimeout="00:10:00" openTimeout="00:10:00" 
         receiveTimeout="00:10:00" sendTimeout="00:10:00"... />

Additionally, I am using service throttling:

<serviceThrottling 
       maxConcurrentCalls="100" 
       maxConcurrentSessions="100" />

Any ideas?

Thanks, Mark.

A: 

You get the error when you reach a certain limit on the number of calls and each call creates it's own proxy.

The error is therefore probably related to the creation or the closing and clean up of the proxy.

You have not posted your code, but you may be able to solve then problem and improve the performance of your code by following these best practices: http://blogs.msdn.com/wenlong/archive/2007/10/27/performance-improvement-of-wcf-client-proxy-creation-and-best-practices.aspx

Another typical problem with async wcf calls is to make sure that the proxy is not closed before the async call returns.

Shiraz Bhaiji