<system.serviceModel>

此組態區段包含所有 Windows Communication Foundation (WCF) ServiceModel 組態元素。

<configuration>
  <system.serviceModel>

Syntax

<system.serviceModel>
  <behaviors>
  </behaviors>
  <bindings>
  </bindings>
  <client>
  </client>
  <comContracts>
  </comContracts>
  <commonBehaviors>
  </commonBehaviors>
  <diagnostics>
  </diagnostics>
  <extensions>
  </extensions>
  <protocolMapping>
  </protocolMapping>
  <routing>
  </routing>
  <serviceHostingEnvironment>
  </serviceHostingEnvironment>
  <services>
  </services>
  <standardEndpoints>
  </standardEndpoints>
  <tracking>
  </tracking>
</system.serviceModel>

屬性和項目

下列章節說明屬性、子元素和父元素。

屬性

子元素

元素 描述
<behaviors> 這個區段會定義兩個名稱為 endpointBehaviorsserviceBehaviors 的子集合。 每個集合會定義分別由端點和服務使用的行為項目。 每個行為項目都由其唯一的 name 屬性所識別。
<bindings> 這個區段保存標準和自訂繫結的集合。 每一個項目都是由它的唯一 name 所識別。 服務會使用 name 來連結繫結,以便利用繫結。
<client> 這個區段包含用戶端用於連接服務之端點的清單。
<comContracts> 這個區段會定義為 WCF 與 COM interop 啟用的 COM 合約。
<commonBehaviors> 這個區段只能定義在 machine.config 檔中。 它會定義兩個名為 endpointBehaviorsserviceBehaviors 的子集合。 每個集合會分別定義由所有 WCF 端點與機器服務所使用的行為元素。 如果 <commonBehaviors><behaviors> 區段都有定義某種行為,則會優先使用 <behaviors> 區段的行為。
<diagnostics> 這個區段包含 WCF 之診斷功能的設定。 使用者可以啟用/停用追蹤、效能計數器和 WMI 提供者,並且可以新增自訂訊息篩選條件。
<extensions> 這個區段包含延伸的集合,可讓使用者建立使用者定義的繫結程序、行為和其他方面的延伸。
<protocolMapping> 這個區段會定義傳輸通訊協定配置 (例如 http、net.tcp、net.pipe 等) 和 WCF 繫結之間的一組預設通訊協定對應。
<routing> 這個區段會定義一組路由篩選條件,這些篩選條件會判斷傳入訊息時所用 Windows Communication Foundation (WCF) 的類別 MessageFilter 及定義當篩選條件相符時傳送訊息的目標端點的路由表。
<serviceHostingEnvironment> 這個區段會定義服務裝載環境為特定傳輸具現化的型別。 如果這個區段是空白的,便會使用預設的型別。
<services> 這個區段包含服務的集合。 對於在組件中定義的各個服務,此項目包含指定服務設定的 service 項目。
<standardEndpoints> 這個區段會定義標準端點的集合,這些端點是可重複使用的預先設定端點。 標準端點會有一個或多個位址、繫結,以及設為固定值的合約屬性。 例如,探索端點中的合約是固定的。 您也可以使用標準端點,以類似定義自訂繫結的新屬性擴充服務端點。
<tracking> 本節會定義工作流程服務的追蹤設定。

父項目

元素 描述
<configuration> .NET 組態檔中所有組態項目的根項目。

備註

WCF 不會在其他產品的組態區段新增項目。

WCF 服務定義於組態檔的 services 區段。 組件可包含任何數目的服務。 各服務都有自己的 service 組態區段。 這個區段及其內容會定義特定服務的服務合約、行為和端點。

只有服務的 name 屬性才需要用到。 根據預設,服務名稱會說明用來實作服務的基礎 CLR 型別,但您可變更 ServiceContractAttribute 上的 ConfigurationName 屬性來覆寫 CLR 型別需求。

behaviorConfiguration 屬性是選擇性的。 它會識別服務使用的服務行為。 此屬性指定的行為必須連結到相同組態檔範圍中 (如同一支檔案或父檔案) 定義的服務行為。

每個服務會公開一個或多個 endpoint 項目中定義的端點。 每個端點都有自己的位址和繫結。 在組態檔中使用的所有繫結都必須定義在檔案的範圍內。

繫結會透過 namebindingConfiguration 屬性的組合連結至端點。 binding 屬性會定義在哪一個區段定義繫結, bindingConfiguration 屬性則會定義使用繫節區段中哪一個已設定的繫結。 繫結區段可定義數個已設定的繫結。

範例

下列是 WCF 組態檔的範例。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.serviceModel>
    <behaviors>
      <!-- List of Behaviors -->
    </behaviors>
    <client>
      <!-- List of Endpoints -->
    </client>
    <diagnostics wmiProviderEnabled="false"
                 performanceCountersEnabled="false"
                 tracingEnabled="false">
    </diagnostics>
    <serviceHostingEnvironment>
      <!-- List of entries -->
    </serviceHostingEnvironment>
    <comContracts>
      <!-- List of COM+ Contracts -->
    </comContracts>
    <services>
      <!-- List of Services -->
    </services>
    <bindings>
      <!-- List of Bindings -->
    </bindings>
  </system.serviceModel>
</configuration>

另請參閱