【问题标题】:WCF Fault HealingWCF 故障修复
【发布时间】:2014-01-10 22:20:07
【问题描述】:

我对这个 WCF 错误处理问题感到沮丧。我已经研究了 3 天了,似乎离解决方案还没有任何距离。

我在How to heal faulted WCF channels?Disposing of WCF Clients 找到了我认为的答案,但我无法让它在我的环境中工作。我正在使用 VB.NET 4.0 并尝试与供应商的服务器进行通信。他们提供了 wsdl 和 xsd 文件,这些文件 svcutil 变成了我已经合并到我的程序中的代理类。

到目前为止,我已经成功地通过了安全问题并实现了 14 个端点中的 13 个。这些似乎工作正常。实例化客户端时,不起作用的返回 Created 的 State 属性:

Dim Client = New InquireBillingInvoiceDetailsPortTypeClient(ConfigName, AppEndPoint)
If Client.State = CommunicationState.Opened Then
    Client.Open()
    ' Code I'm not getting to
Else
    Client.Abort()
    Client = Nothing
End If

我知道通道可能会出现故障,但我不明白为什么在故障条件得到纠正后清除故障条件如此困难。

我也没有得到任何痕迹。与其他端点一样,此服务的客户端和服务器之间没有通信。 svclog 文件中不应该有与此实例化相关的内容吗?这可能有点矫枉过正,但我​​在这里也包括了 app.config 文件的相关部分。任何帮助将不胜感激。

<basicHttpBinding>
   <binding name="InquireBillingInvoiceDetailsSoapHttpBinding"
     closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" 
     sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" 
     hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" 
     maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
     messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
     useDefaultWebProxy="true">
       <readerQuotas maxDepth="32" maxStringContentLength="8192" 
          maxArrayLength="16384" maxBytesPerRead="4096" 
          maxNameTableCharCount="16384" />
       <security mode="Transport">
          <transport clientCredentialType="Certificate" />
       </security>
   </binding>
</basicHttpBinding>

<client>
   <endpoint address="https://.../InquireBillingInvoiceDetails.jws"
      behaviorConfiguration="endPointCredentialBehavior" 
      binding="basicHttpBinding"
      bindingConfiguration="InquireBillingInvoiceDetailsSoapHttpBinding"
      contract="InquireBillingInvoiceDetailsPortType"
      name="InquireBillingInvoiceDetailsSoapHttpPort" />
</client>

<system.diagnostics>
   <sources>
      <source name="System.ServiceModel"
         switchValue="Information, ActivityTracing"
         propagateActivity="true">
         <listeners>
            <add name="xml" />
         </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging" 
         switchValue="All" >
         <listeners>
            <add name="xml" />
          </listeners>
      </sources>

      <sharedListeners>
         <add name="xml"
            type="System.Diagnostics.XmlWriterTraceListener"
            initializeData="U:\logs\Traces.svclog" />
      </sharedListeners>

      <trace autoflush="true" />
</system.diagnostics>

【问题讨论】:

  • 仅供参考……我无法确定您是在询问如何防止故障情况或如何从故障通道中恢复。
  • 我无法控制服务器。我需要从故障通道状态中恢复。
  • 有趣,我想知道您是否可以订阅频道事件,可能是“关闭”或“故障”,然后采取必要的操作来重置连接。
  • 由于这是我第一个使用 WCF 的项目,我正在努力跟上它提供的所有功能。我不确定如何按照您的建议订阅频道事件。这很可能是所需要的,但我的研究导致人们不相信。你有什么编码建议吗?
  • 我看到您从 Tim 那里得到了可能对您有用的答案。我会采取不同的方法。 WCF ClientBase 类具有内置的ChannelFactory 缓存(类似于SqlConnection 连接池)。通过在try/catch 中进行服务调用来利用这一点,您可以在其中为每个服务调用实例化一个新的InquireBillingInvoiceDetailsPortTypeClient 并在catch 中执行Client.Abort()。可能看起来效率低下,但它表现良好并且是管理ClientBase 继承对象的故障保险。见this article.

标签: .net vb.net wcf


【解决方案1】:

CommunicationState.Created不是错误。它只是“表明通信对象已被实例化并且可配置,但尚未打开或准备好使用。”

在您提供的代码 sn-p 中,您正在检查 CommunicationState 是否为 Opening(“表示通信对象正在从 Created 状态转换为 Opened 状态。”),但是您还没有发出Open() 命令,所以它仍然处于Created 状态。这就是您的代码没有到达Client.Open() 语句的原因。

试试这样的:

Dim Client = New InquireBillingInvoiceDetailsPortTypeClient(ConfigName, AppEndPoint)

If Client.State = CommunicationState.Created Then
    Client.Open()
Else
    Client.Abort()
    Client = Nothing
End If

有 6 种状态(此处有详细信息 - CommunicationState Enumeration) - 关闭、关闭、创建、故障、打开、打开。

【讨论】:

    【解决方案2】:

    完成的代码如下所示:

    Dim Client = New InquireBillingInvoiceDetailsPortTypeClient(ConfigName, AppEndPoint)
    
    Client.Open()
    If Client.State = CommunicationState.Opened Then
        ' useful code
    Else
        Client.Abort()
        Client = Nothing
    End If
    

    【讨论】:

      猜你喜欢
      • 2011-01-01
      • 2013-09-09
      • 2012-01-28
      • 2014-06-27
      • 1970-01-01
      • 2019-08-29
      • 2010-12-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多