Share via


<formatter> 項目 (樣板)

包含要插入伺服器或用戶端通道接收鏈結中的格式子接收之通道接收提供者。這個項目包含兩種可能的階層架構。

<configuration>

<system.runtime.remoting>

<channelSinkProviders>

<clientProviders>

<formatter>

這裡指定的格式子會成為 <formatter> 執行個體所使用的樣板。

<configuration>

<system.runtime.remoting>

<channelSinkProviders>

<serverProviders>

<formatter>

這裡指定的格式子也會成為 <formatter> 執行個體所使用的樣板。

<formatter  
   id="FormatterID"
   type="FormatterSinkProviderType, FormatterAssembly"
   customFormatterProperty="customProperty"
   includeVersions="true"
   strictBinding="false"
...typeFilterLevel="Low | Full"
/>

選擇性屬性

屬性 說明

customFormatterProperty

指示支援的自訂通道接收屬性。您可以指定自訂通道接收提供者和其接收可能支援的任何提供者及通道接收屬性數量。自訂通道接收屬性可以是以屬性/值配組指定的。在下列範例中:

<provider id="CustomChannelSinkProvider" type="Namespace.CustomChannelSinkProvider, CustomChannels" customChannelSinkProperty="ChannelSinkPropertyValue"/>

customChannelSinkProperty 屬性及其值將當做提供者之建構函式中的 IDictionary 引數使用。

您也可以在此指定自訂接收提供者資料。不過,只支援一個層級的節點。在下列範例中:

<provider ref="custom">
<extra data="value"/>
<extra data="AnotherValue"/>
</provider>

在提供者的建構函式中,額外資訊將當做 SinkProviderDataICollection 使用。

includeVersions

指示傳送格式子在序列化型別資訊時,要包含完整的型別和組件版本資訊。如需重要的詳細資訊,請參閱下列的<備註>一節。系統所提供兩個格式子的預設值都是 true

strictBinding

指示接收格式子將會先嘗試使用完整的版本資訊 (如果有的話) 來辨識型別,然後才會使用不含版本資訊的型別名稱和組件名稱。如需重要的詳細資訊,請參閱下列的<備註>一節。系統提供的兩個格式子預設都是 false

typeFilterLevel

字串值,指定伺服器通道接收鏈結嘗試中,格式子自動還原序列化的層級。支援的值為 Low (預設值) 和 Full。如需還原序列化層級的詳細資訊,請參閱 .NET 遠端處理中的自動還原序列化

.NET Framework 1.1 版只有在下列平台上才支援這個屬性:Windows 98、Windows NT 4.0、Windows Me、Windows 2000、Windows XP Home (家用版)、Windows XP Professional (商用版)、Windows Server 2003 系列。

必要屬性

屬性 說明

id

指定識別這個格式子接收提供者的字串。而其他通道接收提供者可以在它們的 ref 屬性中使用這個字串,以繫結至這個格式子接收提供者。

type

指定格式子接收提供者的完整型別名稱,以及含有提供者實作的組件名稱。如果包含組件是在全域組件快取中,這個名稱包含版本、文化特性和公開金鑰 (Public Key) 資訊。

備註

由相同應用程式所載入的這個組態檔或其他組態檔其他位置中的 <formatter> 執行個體項目可以參考這裡所指定的格式子。

下表說明當 includeVersionsstrictBinding 屬性同時出現時的互動情形。

includeVersions (傳送格式子) strictBinding (接格式子) 載入型別的方式

true

true

載入實際的型別,否則擲回 TypeLoadException

false

true

只使用型別名稱和組件名稱載入型別,否則擲回 TypeLoadException

true

false

如果有的話,載入實際的型別;如果沒有的話,只使用型別名稱和組件名稱載入型別。如果失敗的話,擲回 TypeLoadException

false

false

只使用型別名稱和組件名稱載入型別,否則擲回 TypeLoadException

範例

因為下列組態檔使用 <clientProviders> 執行個體,您必須指定所有您想要通道使用的格式子或提供者。在此情況中,<formatter> 項目參考 SoapClientFormatterSink,而且使用 <provider> 執行個體項目來指派 "propsetter" 和 "null" 通道接收提供者 (它們本身是以 <provider> 樣板項目宣告的) 給 HttpChannel。此外,"propsetter" 通道接收提供者是以自訂提供者屬性 (Property) 所建立的,而這些屬性 (Property) 已指定為提供者執行個體項目上的屬性 (Attribute),以及子代 <endpoint> 屬性 (Attribute) 的名稱/值組。

<configuration>
   <system.runtime.remoting>
      <application>
         <client>
            <wellknown 
               type="RemoteType, RemoteAssembly"
               url="http://computername:8080/RemoteType.rem"/>
         </client>
         <channels>
            <channel ref="http">
               <clientProviders>
                  <formatter ref="soap"/>
                  <provider 
                     ref="propsetter" 
                     username="bob" 
                     writeToConsole="true"
                  >
                     <endpoint url="contoso.com:9000" someProperty="xyz" />
                     <endpoint url="contoso.com:9001" someProperty="123" />
                  </provider>
                  <provider ref="null" writeToConsole="true" />
               </clientProviders>
            </channel>
         </channels>
      </application>
      <channelSinkProviders>
         <clientProviders>
            <provider 
               id="propsetter" 
               type="ChannelSinkPropertySetterProvider, SinkAssembly" 
            />
            <provider 
               id="null" 
               type="NullSinkProvider, SinkAssembly" 
            />
         </clientProviders>
      </channelSinkProviders>
      <debug loadTypes="true" />
   </system.runtime.remoting>
</configuration>

需求

**組態檔:**應用程式組態檔、電腦組態檔 (Machine.config)

請參閱

參考

遠端設定結構描述
BinaryClientFormatterSink
SoapClientFormatterSink
BinaryServerFormatterSink
SoapServerFormatterSink

Footer image

Copyright © 2007 by Microsoft Corporation. All rights reserved.