什么处理我的WCF对象以及为什么?

时间:2015-11-17 15:34:57

标签: c# .net wcf

我有一个使用WCF与远程服务器通信的应用程序。经常,相对可预测的是,我在日志中显示ObjectDisposedException,我无法弄清楚原因。看起来WCF对象本身已经被处理掉了。到目前为止,我已经看到这些对象类型被丢弃,并抛出异常:

  • System.ServiceModel.Channels.HttpChannelFactory'1+HttpRequestChannel[System.ServiceModel.Channels.IRequestChannel]
  • System.ServiceModel.Channels.ServiceChannel

我收集了WCF跟踪信息,每次以这种方式失败的调用都遵循相同的模式:

  1. 跟踪转移,来自
  2. 活动边界,开始
  3. 消息日志跟踪
  4. 抛出异常
  5. 跟踪转移,
  6. 我的代码中没有任何内容明确地处理服务客户端。实际上,我只是自己传递服务契约接口,并且它们没有实现IDisposable,所以例如using块不太可能是罪魁祸首。

    正如我之前所说,我可以重现这些错误是相对可预测的;但是,我无法通过特定的服务契约接口预测它,更不用说在该接口上进行特定的方法调用了。它移动了一下。有时第一次呼叫失败,有时在几次呼叫后失败。

    我已经排除了网络连接问题。我能做些什么来隔离这些例外的来源;即我的CommunicationObject派生对象被处置的核心原因,或者在我的异常日志记录中将这些视为良性我唯一选择的特殊情况?

    更新

    我正在使用渠道工厂来创建我的服务合同接口的实例。我不是在缓存/重用那些渠道工厂。我还有一些IMessageInspector实施通过IEndpointBehavior连接并通过channelFactory.Endpoint.Behaviors.Add(...)附加。我正在以编程方式执行所有操作,而不是按配置驱动,所以有很多代码在运行,因此它不会被发布。

    示例堆栈跟踪:

    System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposedOrNotOpen()
    System.ServiceModel.Channels.RequestChannel.BeginRequest(Message message, TimeSpan timeout, AsyncCallback callback, Object state)
    System.ServiceModel.Dispatcher.RequestChannelBinder.BeginRequest(Message message, TimeSpan timeout, AsyncCallback callback, Object state)
    System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.StartSend(Boolean completedSynchronously)
    System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.FinishEnsureOpen(IAsyncResult result, Boolean completedSynchronously)
    System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.StartEnsureOpen(Boolean completedSynchronously)
    System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.FinishEnsureInteractiveInit(IAsyncResult result, Boolean completedSynchronously)
    System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.StartEnsureInteractiveInit()
    System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.Begin()
    System.ServiceModel.Channels.ServiceChannel.BeginCall(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, TimeSpan timeout, AsyncCallback callback, Object asyncState)
    System.ServiceModel.Channels.ServiceChannelProxy.InvokeBeginService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
    System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
    System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
    <truncated, my application-level code is at this level>
    

    我在网上搜索过,我已经反编译了WCF内部,我已经调试过,收集了跟踪日志。我做完了我的作业。正如您在编辑历史记录中看到的那样,每次有人要求时我都会添加详细信息。如果你有任何贡献,包括“你不应该这样做”,请跳进去。

1 个答案:

答案 0 :(得分:1)

所以我发现了这个问题。一个未受管理的组件正在爆炸并在内存上涂鸦。 CLR能够(在某种程度上)减轻大屠杀,但是WCF例外是一个红色的鲱鱼。