关于捕获FaultException前任

发布于 2024-08-14 05:55:53 字数 2184 浏览 7 评论 0原文

我在应用程序的服务器端使用企业应用程序块来处理异常。

我能够成功处理异常。我创建了一个自定义服务故障类来处理异常。

这是我的网络配置输入...

<exceptionPolicies>
  <add name="WCF Exception Shielding">
    <exceptionTypes>
      <add type="TEST.Infrastructure.ExceptionHandling.Exceptions.TESTBusinessException, Pluto.Infrastructure.ExceptionHandling, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
      postHandlingAction="ThrowNewException" name="TESTBusinessException">
        <exceptionHandlers>
          <add logCategory="BusinessLoggingCategory" eventId="501" severity="Error"
            title="Pluto Service Exception" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
            priority="0" useDefaultLogger="false" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            name="Logging Handler" />
          <add
            type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            name="DefaultFaultContract Handler"
            faultContractType="TEST.Infrastructure.ExceptionHandling.Exceptions.TESTServiceException, Pluto.Infrastructure.ExceptionHandling"
            exceptionMessage="Pluto.Infrastructure.ExceptionHandling.Exceptions.TESTBusinessException {handlingInstanceID}">
            <mappings>
              <add name="Id" source="{Guid}"/>
              <add name="MessageText" source="{Message}"/>
            </mappings>
          </add>
        </exceptionHandlers>
      </add>

但是在客户端,当我尝试捕获此异常时,因为

 catch (FaultException<TESTServiceException> fex) 
        { 
        }

此异常未被捕获。 我能够在客户端获取我在服务器端的 app.config 中编写的异常消息。

任何人都可以帮我解决这个问题吗?

预先感谢

维克拉姆

I am using Enterprise application block on my application' server side to handle exceptions.

I am able to successfully handle exception. I have created a custom service fault class to handle exceptions.

Here are my web config enteries...

<exceptionPolicies>
  <add name="WCF Exception Shielding">
    <exceptionTypes>
      <add type="TEST.Infrastructure.ExceptionHandling.Exceptions.TESTBusinessException, Pluto.Infrastructure.ExceptionHandling, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
      postHandlingAction="ThrowNewException" name="TESTBusinessException">
        <exceptionHandlers>
          <add logCategory="BusinessLoggingCategory" eventId="501" severity="Error"
            title="Pluto Service Exception" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
            priority="0" useDefaultLogger="false" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            name="Logging Handler" />
          <add
            type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            name="DefaultFaultContract Handler"
            faultContractType="TEST.Infrastructure.ExceptionHandling.Exceptions.TESTServiceException, Pluto.Infrastructure.ExceptionHandling"
            exceptionMessage="Pluto.Infrastructure.ExceptionHandling.Exceptions.TESTBusinessException {handlingInstanceID}">
            <mappings>
              <add name="Id" source="{Guid}"/>
              <add name="MessageText" source="{Message}"/>
            </mappings>
          </add>
        </exceptionHandlers>
      </add>

But on the client side when i try to catch this exception as

 catch (FaultException<TESTServiceException> fex) 
        { 
        }

this exception is not caught.
I am able to get the exception message on the client side which i have writen in app.config on server side.

Can any one please help me figure out the problem.

Thanks in advance

Vikram

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最舍不得你 2024-08-21 05:55:53

尝试使用XmlReader提取异常详细信息:

catch (FaultException ex)
{
    string msg = "FaultException: " + ex.Message;
    MessageFault fault = ex.CreateMessageFault();
    if (fault.HasDetail)
    {
        System.Xml.XmlReader reader = fault.GetReaderAtDetailContents();
        if (reader.Name == "TESTServiceException")
        {
            TESTServiceException detail = fault.GetDetail<TESTServiceException>();
            msg += "\n\nStack Trace: " + detail.SomeTraceProperty;
        }
    }
    MessageBox.Show(msg);
}

有关捕获故障异常的更多说明此处此处

Try extracting the exception details using the XmlReader:

catch (FaultException ex)
{
    string msg = "FaultException: " + ex.Message;
    MessageFault fault = ex.CreateMessageFault();
    if (fault.HasDetail)
    {
        System.Xml.XmlReader reader = fault.GetReaderAtDetailContents();
        if (reader.Name == "TESTServiceException")
        {
            TESTServiceException detail = fault.GetDetail<TESTServiceException>();
            msg += "\n\nStack Trace: " + detail.SomeTraceProperty;
        }
    }
    MessageBox.Show(msg);
}

More explanation on catching fault exceptions here and here.

暖伴 2024-08-21 05:55:53

您是否在操作上定义了故障契约?

[FaultContract(typeof(TESTServiceException))]

您是否在服务合同上定义了 [ExceptionShielding] 属性?

还应设置以下服务行为

 <behaviors>
      <serviceBehaviors>
        <behavior name="StandardBehaviour">
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
 </behaviors>

Have you defined fault contract on the operation ?

[FaultContract(typeof(TESTServiceException))]

Have you defined the [ExceptionShielding] attribute on the service contract ?

Also the following service behavior should be set

 <behaviors>
      <serviceBehaviors>
        <behavior name="StandardBehaviour">
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
 </behaviors>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文