CommunicationObjectAbortedException occurrs when WCF Client waits for an asynchronous return from self hosted service
I have a WCF client that creates a self hosted service. The client will eventually host other service endpoints, so the client maintains a list of service references locally, m_services, and invokes the service methods on each endpoint maintained. The ServiceHost is created, and the client is created at the endpoint. A few setup calls are made to the service succesfully.
Another call to the service is made, which returns quickly, but then the client waits for an asychronous return to a callback delegate. There are numerous callback calls that are made, about 1 a second over about a 5 minute period, waiting for a specific callback method with data passed in.
While the client is waiting for a response, I eventually get the following exceptions to my output console.
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
Below is the code that I use to build up the ServiceHost for the self hosted service. Am I doing something incorrectly with setting up my ServiceHost and client? I'm not sure why initially, the client is responsive to calls and gives expected results, but eventually gets faulted and the communication object is aborted. Initially I had the ServiceHost as a local variable to the method that was creating it, but promoted it to a field of the class, thinking that it might have been garbage collected.
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 DllAnalyzerSe开发者_运维问答rviceClient(m_instanceContext, binding, endpointAddress);
m_selfHost.Open();
service.Subscribe();
service.DynamicallyLoadDll(crxDllFile);
m_services.Add(service);
I believe the reason I was experiencing these problems is becuase the service was timing out due to inactivity, as I noticed it was timing out at the default value of 10 minutes. In the service's app.config, I create a default Dual HTTP Binding scheme that set the timeout to infinite.
What i'm unsure about though is why I was getting CommunicationObjectAbortedException, and not a Timeout Exception, which other sources I found indicate that you would get. Perhaps it differs depending on the binding mode?
<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>
精彩评论