【问题标题】:Does OperationContextScope dispose communication channel as well?OperationContextScope 是否也配置了通信通道?
【发布时间】:2014-02-13 13:27:04
【问题描述】:

OperationContextScope 是否在处置通信通道时也处置它?

在以下示例中,当ServiceMethod 第二次执行时,我得到一个“通信对象 System.ServiceModel.Channels.ServiceChannel,因为它处于故障状态,因此无法用于通信”异常:

clientProxy = ...
public int ServiceMethod()
{
   using(OperationContextScope c = new OperationContextScope((IClientChannel)clientProxy))
   {
      //Add request header
      OperationContext.Current.OutgoingMessageHeaders.Add(...)
      clientProxy.method(...); //When this execute the second time, a fault state exception occur
   }

   //Add reply header
   OperationContext.Current.OutgoingMessageHeaders.Add(...)
   return 1;
}

另外,如果是重要信息,clientProxy.method() 会传递一个回调。

【问题讨论】:

    标签: c# wcf operationcontext


    【解决方案1】:

    显然,答案是否定的。我有一个抛出未捕获异常的 OneWay 方法。该异常从未在服务或客户端中显示,因此很难捕获。处理这个问题就解决了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-04
      • 2016-08-14
      • 2019-04-16
      • 2022-08-24
      • 2017-06-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多