ServiceDebugBehavior 類別

定義

啟用 Windows Communication Foundation (WCF) 服務的偵錯和說明資訊功能。

public ref class ServiceDebugBehavior : System::ServiceModel::Description::IServiceBehavior
public class ServiceDebugBehavior : System.ServiceModel.Description.IServiceBehavior
type ServiceDebugBehavior = class
    interface IServiceBehavior
Public Class ServiceDebugBehavior
Implements IServiceBehavior
繼承
ServiceDebugBehavior
實作

範例

下列程式碼範例示範如何使用組態檔來啟用 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>

備註

從組態檔使用 ServiceDebugBehavior 屬性或以程式設計的方式讓 Managed 例外狀況資訊的流量進入用戶端以便偵錯,以及發行可讓使用者在 Web 瀏覽器中瀏覽服務的 HTML 資訊檔案。

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

警告

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

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

如需與 Managed 例外狀況資訊相關的安全性問題詳細資訊,請參閱 在合約和服務中指定及處理錯誤

HttpHelpPageEnabledHttpsHelpPageEnabled 屬性會在使用 HTML 瀏覽器檢視服務時,指示服務要發行 HTML 說明檔案。

HttpHelpPageUrlHttpsHelpPageUrl 屬性會控制所檢視的 HTML 說明頁的位置。

如果要使用組態檔啟用或停用其中一項 ServiceDebugBehavior 功能:

  1. behaviorConfiguration將 屬性新增至< WCF 服務的服務 >元素。 端點行為是在端點 > 元素上 <設定;服務元素上的< 服務 >行為。

  2. 將 新增至或建立< serviceBehaviors >區段,並將行為 > 專案新增 <至,其名稱符合 behaviorConfiguration 步驟 1 的屬性值。 端點行為是使用< endpointBehaviors 元素來設定;服務行為是使用 serviceBehaviors >> 元素來設定。 <

  3. < 將 serviceDebug >元素新增至步驟 2的行為專案, <>並啟用或停用適合您案例的各種屬性。

如需特定範例,請參閱<範例>一節。

建構函式

ServiceDebugBehavior()

初始化 ServiceDebugBehavior 類別的新執行個體。

屬性

HttpHelpPageBinding

取得或設定繫結定義的高層級存取權。

HttpHelpPageEnabled

取得或設定值,控制 Windows Communication Foundation (WCF) 是否在由 HttpHelpPageUrl 屬性控制的位址發佈 HTML 說明頁。

HttpHelpPageUrl

取得或設定 HTML 說明檔的發行位置。

HttpsHelpPageBinding

取得或設定繫結定義的高層級存取權。

HttpsHelpPageEnabled

取得或設定值,指定 Windows Communication Foundation (WCF) 是否會在由 HttpsHelpPageUrl 屬性所控制的位址,透過 HTTPS 傳回 HTML 說明檔。

HttpsHelpPageUrl

取得或設定發行 HTML 檔案以使用 HTTPS 進行擷取的位置。

IncludeExceptionDetailInFaults

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

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

IServiceBehavior.AddBindingParameters(ServiceDescription, ServiceHostBase, Collection<ServiceEndpoint>, BindingParameterCollection)

實作 AddBindingParameters(ServiceDescription, ServiceHostBase, Collection<ServiceEndpoint>, BindingParameterCollection) 方法以支援這個行為。

IServiceBehavior.ApplyDispatchBehavior(ServiceDescription, ServiceHostBase)

實作 ApplyDispatchBehavior(ServiceDescription, ServiceHostBase) 方法以支援這個行為。

IServiceBehavior.Validate(ServiceDescription, ServiceHostBase)

實作 Validate(ServiceDescription, ServiceHostBase) 方法以支援這個行為。

適用於