当WCF客户端等待从自托管服务的异步返回时,会发生CommunicationObjectAbortedException

时间:2011-04-08 17:48:01

标签: c# wcf

我有一个WCF客户端,可以创建自托管服务。客户端最终将托管其他服务端点,因此客户端在本地维护一个服务引用列表,m_services,并在维护的每个端点上调用服务方法。创建ServiceHost,并在端点创建客户端。成功进行了一些设置调用。

对服务进行另一次调用,该调用快速返回,但随后客户端等待异步返回回调委托。有大量的回调调用,在大约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);

1 个答案:

答案 0 :(得分:1)

我相信我遇到这些问题的原因是因为服务因不活动而超时,因为我注意到它的默认值为10分钟。在服务的app.config中,我创建了一个默认的双HTTP绑定方案,将超时设置为无限。

我不确定的是,为什么我得到CommunicationObjectAbortedException,而不是Timeout Exception,我发现的其他来源表明你会得到。也许它根据绑定模式而有所不同?

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