2009-11-12 256 views
5

我有重現,我有我的真實WCF應用程序有問題的樣本WCF項目。 您可以下載我的樣本WCF應用程序here通信對象不能用於通信,因爲它已被中止

Accoding的超時設置代碼和配置文件的源代碼,我不明白什麼是appening:

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

回答

1

看起來你是路過例外返回給客戶端。 WCF不喜歡常規的異常,它在錯誤的情況下需要fauls或FaultException。返回異常後,通道處於故障狀態,不能再次使用。發生FaultException後,通道仍然可用。

+0

你是對的,但異常沒有被我的代碼拋出。它由WCF基礎設施拋出。我不想知道爲什麼拋出這個異常以及如何避免它。我知道我的服務正在運行10分鐘,但根據超時設置,我不理解這個例外。 – Sebastien 2009-11-12 19:27:35

+2

首先要做的是在服務中啓用完全跟蹤。這通常會給你很多關於原始問題的信息。 – Maurice 2009-11-13 16:47:47

6

我們也有類似的問題,因爲託管服務的應用程序池被配置爲具有最大工作進程大於1對於呼叫中止或關閉的成功,它需要被路由到處理的相同的服務實例原始請求。

+1

感謝發佈此消息,我在客戶分段環境中遇到了完全相同的問題。他們的一位開發人員將「最大工作者流程」設置爲5,導致這些例外。我們在地方使用wsfederationhttpbinding,有一個安全令牌服務(STS)也使得它被扔更加混亂異常 - 這表明令牌無效。事實上,這個要求有時只是針對錯誤的工作流程。 – 2012-08-22 12:58:31

+0

我們觀察到同樣的問題,我們使用wshttpbinding和消息安全性。讓Web服務機器前面的Netscalar負載均衡器使分類變得更加困難。我們最初認爲LB沒有保持粘稠的會話,並試圖看看是否將LB從等同中解決問題。但是,當我們注意到Maximum Worker Processes設置設置爲1以上時,它沒有。 – 2016-01-11 22:17:42

2

我,我做了一個WCF服務的異步調用類似的問題。在async_completed方法中收到結果後,我得到一個異常。

「在操作過程中出現的異常,使結果無效檢查的InnerException爲例外。」

的InnerException:
「通信對象不能用於通信,因爲它已被中止」

了很大的功夫我找到解決方案後,正好趕上例外,而不在async_completed方法拋出。 (即實施try/catch)。我不明白什麼是確切的問題,但不知何故溝通渠道正在打破。

我試過上述計算策略從以下鏈接

http://geekswithblogs.net/SoftwareDoneRight/archive/2008/05/23/clean-up-wcf-clients--the-right-way.aspx

不過我不相信這是正確的做法,但按照我的操作結果的情況我不是furtherly做任何事情。所以它正在捕捉異常並停止服務。

相關問題