ServiceDebugBehavior.IncludeExceptionDetailInFaults 屬性

定義

取得或設定值,指定是否要在傳回至用戶端以進行偵錯的 SOAP 錯誤詳細資料中包含 Managed 例外狀況資訊。

public:
 property bool IncludeExceptionDetailInFaults { bool get(); void set(bool value); };
public bool IncludeExceptionDetailInFaults { get; set; }
member this.IncludeExceptionDetailInFaults : bool with get, set
Public Property IncludeExceptionDetailInFaults As Boolean

屬性值

Boolean

true如果 Windows Communication Foundation (WCF) 針對用戶端偵錯而傳回 SOAP 錯誤中的 Managed 例外狀況資訊,則為 ,否則 false 為 。 預設為 false

範例

下列程式碼範例示範如何使用組態檔來啟用 HTML 說明頁功能,並將 SOAP 錯誤內部的例外狀況資訊傳回至用戶端,以供偵錯之用。 這個組態檔會示範下列基本步驟來加入 ServiceDebugBehavior 功能的支援:

<configuration>
  <system.serviceModel>
    <services>
      <!-- 
        Step 1. Add a behaviorConfiguration attribute
        in the <service> element.
      -->
      <service 
        name="Microsoft.WCF.Documentation.SampleService"
        behaviorConfiguration="metadataAndDebug">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/SampleService" />
          </baseAddresses>
        </host>
        <endpoint
          address=""
          binding="wsHttpBinding"
          contract="Microsoft.WCF.Documentation.ISampleService"
        />
        <endpoint
           address="mex"
           binding="mexHttpBinding"
           contract="IMetadataExchange"
        />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <!-- 
          Step 2. Inside a <serviceBehaviors> section, add 
          a name attribute in the <behaviors> element that 
          matches the behaviorConfiguration attribute in the
          <service> element above.
        -->
        <behavior name="metadataAndDebug">
          <serviceMetadata 
            httpGetEnabled="true" 
            httpGetUrl=""
          />
          <!-- 
            Step 3. Add a <serviceDebug> element and 
            modify the various attributes that suit your 
            scenario.
          -->
          <serviceDebug 
            httpHelpPageEnabled="true" 
            includeExceptionDetailInFaults="true"
          />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

備註

IncludeExceptionDetailInFaults 屬性設定為 true ,以指示 WCF 將 Managed 例外狀況資訊傳回 SOAP 錯誤中的用戶端,以簡化偵錯。

警告

將 Managed 例外狀況資訊傳回用戶端可能導致安全性風險,因為例外狀況詳細資料會公開未授權的用戶端可使用的內部服務實作相關資訊。 此外,雖然也能以程式設計方式設定 ServiceDebugBehavior 屬性,不過在部署時很容易會忘記停用 IncludeExceptionDetailInFaults

由於牽涉到安全性議題,我們強烈建議您:

如需詳細資訊,請參閱 在合約和服務中指定及處理錯誤

適用於