ServiceDebugBehavior 类  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
启用 Windows Communication Foundation (WCF) 服务的调试和帮助信息功能。
public ref class ServiceDebugBehavior : System::ServiceModel::Description::IServiceBehaviorpublic class ServiceDebugBehavior : System.ServiceModel.Description.IServiceBehaviortype ServiceDebugBehavior = class
    interface IServiceBehaviorPublic Class ServiceDebugBehavior
Implements IServiceBehavior- 继承
- 
				ServiceDebugBehavior
- 实现
示例
下面的代码示例演示如何使用配置文件来启用 HTML 帮助页功能,将 SOAP 错误内部的异常信息返回给客户端以供调试,以及启用元数据支持。 此配置文件演示以下用于添加对 ServiceDebugBehavior 功能的支持的基本步骤:
- 由于 类型 ServiceDebugBehavior 是实现 System.ServiceModel.Description.IServiceBehavior , <因此表示服务类型的 service> 元素的行为配置标识符为 - behaviorConfiguration="metadataAndDebug"。
- 由于 类型ServiceDebugBehavior是实现System.ServiceModel.Description.IServiceBehavior,因此<会将行为>元素添加到 <serviceBehaviors> 节。 - name设置行为>元素的< 属性,其值是服务>元素特性的<标识符- behaviorConfiguration。 在本例中,该值为- metadataAndDebug。
- 添加 serviceDebug<> 元素,并将各种属性设置为所需配置。 在本例中, - httpHelpPageEnabled和- includeExceptionDetailInFaults属性值设置为- true。
<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 属性,可以使托管异常信息流到客户端以进行调试,还可以向在 Web 浏览器中浏览该服务的用户发布 HTML 信息文件。
将 IncludeExceptionDetailInFaults 属性设置为 以 true 指示 WCF 将 SOAP 错误中的托管异常信息返回给客户端以进行调试。
注意
将托管异常信息返回给客户端可能存在安全风险,因为异常详细信息会公开有关内部服务实现的信息,而未经授权的客户端可能会利用这些信息。 此外,虽然 ServiceDebugBehavior 属性也可以通过编程方式进行设置,但在部署时容易忘记禁用 IncludeExceptionDetailInFaults。
由于涉及到一些安全问题,因此强烈建议您:
- 使用应用程序配置文件将 IncludeExceptionDetailInFaults 属性的值设置为 - true。
- 仅在受控调试方案中才这样做。 
有关与托管异常信息相关的安全问题的详细信息,请参阅 在协定和服务中指定和处理错误。
当使用 HTML 浏览器查看服务时,HttpHelpPageEnabled 和 HttpsHelpPageEnabled 属性指示服务发布 HTML 帮助文件。
HttpHelpPageUrl 和 HttpsHelpPageUrl 属性控制所查看的 HTML 帮助页的位置。
若要使用配置文件启用或禁用其中一个 ServiceDebugBehavior 功能,请执行以下操作:
- 将 - behaviorConfiguration特性添加到 <WCF 服务的 service> 元素。 终结点行为在终结点>元素上<配置;服务元素上的<服务>行为。
- 将 添加到或创建 <serviceBehaviors> 节,并在其中添加一个<行为>元素,其名称与步骤 1 中的 - behaviorConfiguration属性值匹配。 终结点行为是使用 <endpointBehaviors> 元素配置的;服务行为是使用 <serviceBehaviors> 元素配置的。
- 将 <serviceDebug> 元素添加到步骤 2 中的 <behavior> 元素,并启用或禁用适合你的方案的各种属性。 
有关具体示例的信息,请参见“示例”部分。
构造函数
| 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 错误详细信息中是否包含托管异常信息。 | 
方法
| Equals(Object) | 确定指定对象是否等于当前对象。(继承自 Object) | 
| GetHashCode() | 作为默认哈希函数。(继承自 Object) | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| ToString() | 返回表示当前对象的字符串。(继承自 Object) |