2

我收到来自 WCF 客户端的“无法处理消息...”错误。请帮助,它正在杀死我。

我有一个测试获胜应用程序,它通过一个for循环来启动x个异步调用。每个异步调用都会实例化它自己的 WCF 代理实例,并使用该代理调用 WCF 服务。如果x约为 35 或更小,则一切正常。如果x > 40 左右,许多调用都可以正常完成,但少数会返回:

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 ...

我正在使用具有消息安全性的客户端和服务器端证书。我不明白为什么它只运行了一定次数,然后呕吐。它似乎也会在接近迭代结束的调用上引发错误。此外,此错误发生在我的任何超时之前很久,在客户端和服务器端设置相同:

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

此外,我正在使用服务限制:

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

有任何想法吗?

谢谢,马克。

4

1 回答 1

0

当您达到呼叫数量的特定限制并且每个呼叫创建它自己的代理时,您会收到错误消息。

因此,该错误可能与代理的创建或关闭和清理有关。

您尚未发布您的代码,但您可以通过以下最佳实践来解决问题并提高代码性能:http: //blogs.msdn.com/wenlong/archive/2007/10/27/performance -wcf-client-proxy-creation-and-best-practices.aspx 的改进

异步 wcf 调用的另一个典型问题是确保在异步调用返回之前未关闭代理。

于 2010-01-23T12:27:55.093 回答