我有一个示例WCF项目,它重现了我在真正的WCF应用程序中遇到的问题。 您可以下载我的示例WCF应用程序here
的源代码根据代码和配置文件中的超时集,我不明白出现了什么:
**** Server exception : System.ServiceModel.CommunicationObjectAbortedException:
The communication object, System.ServiceModel.Security.SecuritySessionServerSettings+SecurityReplySessionChannel, cannot be used for communication because it
has been Aborted.
at System.ServiceModel.Channels.CommunicationObject.ThrowIfClosedOrNotOpen()
at System.ServiceModel.Security.SecuritySessionServerSettings.ServerSecuritySessionChannel.SecureApplicationMessage(Message& message, TimeSpan timeout, SecurityProtocolCorrelationState correlationState)
at System.ServiceModel.Security.SecuritySessionServerSettings.SecuritySessionRequestContext.OnReply(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.RequestContextBase.Reply(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.RequestContextBase.Reply(Message message)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.Reply(MessageRpc& rpc)
**** client exception : : 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://schemas.xmlsoap.org/ws/2005/02/trust/RST/SCT/Cancel' 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.ClientSecuritySessionChannel.ProcessRequestContext(RequestContext requestContext, TimeSpan timeout, SecurityProtocolCorrelationState correlationState)
at System.ServiceModel.Security.SecuritySessionClientSettings`1.ClientSecuritySessionChannel.ReceiveInternal(TimeSpan timeout, SecurityProtocolCorrelationState correlationState)
at System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.CloseOutputSession(TimeSpan timeout)
at System.ServiceModel.Security.SecuritySessionClientSettings`1.ClientSecuritySessionChannel.CloseSession(TimeSpan timeout, Boolean& wasAborted)
at System.ServiceModel.Security.SecuritySessionClientSettings`1.ClientSecuritySessionChannel.OnClose(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.OnClose(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
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 System.ServiceModel.ICommunicationObject.Close(TimeSpan timeout)
at System.ServiceModel.ClientBase`1.System.ServiceModel.ICommunicationObject.Close(TimeSpan timeout)
at System.ServiceModel.ClientBase`1.Close()
at System.ServiceModel.ClientBase`1.System.IDisposable.Dispose()
at WindowsFormsApplication1.Program.Main() in C:\Users\sdoucet\Documents\Visual Studio 2008\Projects\TestWCFLongExecution\WindowsFormsApplication1\Program.cs:line 25
答案 0 :(得分:7)
我们遇到了类似的问题,因为托管服务的应用程序池配置为最大工作进程数大于1.要调用Abort或Close成功,需要将其路由到处理原始数据的同一服务实例请求。
答案 1 :(得分:2)
我有一个类似的问题,我做了一个wcf服务异步调用。在async_completed方法中收到结果后,我得到了一个例外。
"操作期间发生异常,导致结果无效。检查InnerException是否有例外"
的InnerException:
"通讯对象不能用于通讯,因为它已被中止"
经过大量的努力,我找到了解决方案,只需捕获异常而不抛出async_completed方法。 (即实施了try / catch)。我不明白究竟是什么问题,但不知何故,沟通渠道正在破裂。
我从以下链接尝试了以上approch
我仍然不相信这是正确的方法,但根据我的操作结果,我没有做任何进一步的事情。所以它正在捕捉异常并停止服务。
答案 2 :(得分:1)
看起来您正在将异常传递回客户端。 WCF不喜欢常规异常,它在发生错误时需要fauls或FaultException。返回异常并且异常返回后,通道处于故障状态,无法再次使用。在FaultException之后,通道仍然可用。