2011-04-08 83 views
0

我有一個創建自託管服務的WCF客戶端。客戶端最終將託管其他服務端點,因此客戶端在本地維護服務引用列表m_services,並調用維護的每個端點上的服務方法。 ServiceHost已創建,客戶端在端點上創建。一些安裝調用成功完成了服務。WCF客戶端等待自託管服務異步返回時發生CommunicationObjectAbortedException

另一個對服務的調用會很快返回,但客戶端會等待異步返回到回調委託。有大量的回調調用,約5分鐘時間約1秒,等待傳入數據的特定回調方法。

當客戶端正在等待響應時,我最終得到以下異常到我的輸出控制檯。

A first chance exception of type 'System.ServiceModel.CommunicationObjectAbortedException' occurred in System.ServiceModel.dll A first chance exception of type 'System.ServiceModel.CommunicationObjectAbortedException' occurred in System.ServiceModel.dll A first chance exception of type 'System.ServiceModel.CommunicationObjectAbortedException' occurred in System.Runtime.DurableInstancing.dll A first chance exception of type 'System.ServiceModel.CommunicationObjectAbortedException' occurred in System.Runtime.DurableInstancing.dll A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.Runtime.DurableInstancing.dll

下面是我用的建立爲自託管服務ServiceHost的代碼。我是否在設置我的ServiceHost和客戶端時做了不正確的事情?我不確定爲什麼最初,客戶端對呼叫作出響應並給出了預期的結果,但最終出現故障並且通信對象被中止。最初,我將ServiceHost作爲創建它的方法的局部變量,但將其提升到類的字段,認爲它可能已被垃圾收集。

m_selfHost = new ServiceHost(hostType); 
var binding = new WSDualHttpBinding(); 
ContractDescription contractDescription = 
    ContractDescription.GetContract(contractType); 
EndpointAddress endpointAddress = new EndpointAddress(Properties.Settings.Default.SelfHostedServiceUrl); 
ServiceEndpoint endpoint = new ServiceEndpoint(contractDescription, binding, endpointAddress); 
m_selfHost.AddServiceEndpoint(endpoint); 

DllAnalyzerServiceClient service = new DllAnalyzerServiceClient(m_instanceContext, binding, endpointAddress); 
m_selfHost.Open(); 
service.Subscribe(); 
service.DynamicallyLoadDll(crxDllFile); 
m_services.Add(service); 
+0

難道是回調通道產生異常錯誤信息? – 2012-02-01 20:18:06

回答

1

我相信我遇到這些問題的原因是監守該服務超時由於不活動,因爲我發現它是在10分鐘的默認值超時。在服務的app.config中,我創建了一個默認的雙HTTP綁定方案,將超時設置爲無限。

我不確定的是,爲什麼我得到CommunicationObjectAbortedException,而不是一個超時異常,我發現其他來源表明你會得到。也許它根據綁定模式而有所不同?

<system.serviceModel> 
    <bindings> 
     <wsDualHttpBinding> 
     <binding name="DefaultDualHttpBinding" receiveTimeout="Infinite"> 
      <reliableSession inactivityTimeout="Infinite" /> 
     </binding> 
     </wsDualHttpBinding> 
    </bindings> 
    <services> 
     <service behaviorConfiguration="DllAnalyzerService.Service1Behavior" 
     name="DllAnalyzerService.DllAnalyzerService"> 
     <endpoint address="" binding="wsDualHttpBinding" bindingConfiguration="DefaultDualHttpBinding" 
      contract="DllAnalyzerService.IDllAnalyzerService"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8732/Design_Time_Addresses/DllAnalyzerService/DllAnalyzerService/" /> 
      </baseAddresses> 
     </host> 
     </service> 
    </services>