多次异步调用 WCF 期间出现异常(无法处理消息...)

发布于 2024-08-19 02:14:28 字数 2609 浏览 5 评论 0原文

我收到来自 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" />

有什么想法吗?

谢谢,马克。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦冥 2024-08-26 02:14:28

当您达到调用次数的特定限制并且每个调用都会创建自己的代理时,您会收到错误消息。

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

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文