2

アプリケーションのサーバー側でエンタープライズアプリケーションブロックを使用して、例外を処理しています。

例外を正常に処理できます。例外を処理するためのカスタムサービス障害クラスを作成しました。

これが私のWeb設定エントリです...

<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に書き込んだ例外メッセージをクライアント側で受け取ることができます。

誰かが私が問題を理解するのを手伝ってくれませんか。

前もって感謝します

ヴィクラム

4

2 に答える 2

2

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);
}

ここここで障害例外をキャッチするための詳細な説明。

于 2010-06-04T16:50:39.947 に答える
0

操作の障害契約を定義しましたか?

[FaultContract(typeof(TESTServiceException))]

サービス契約で[ExceptionShielding]属性を定義しましたか?

また、次のサービス動作を設定する必要があります

 <behaviors>
      <serviceBehaviors>
        <behavior name="StandardBehaviour">
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
 </behaviors>
于 2009-12-09T10:50:18.633 に答える