<channel> 項目 (樣板)

包含應用程式可以指定及設定的通道樣板,以便與遠端物件的要求進行通訊,或接聽遠端物件的要求。通道可以註冊在任何位置上以供使用,而您可以將該執行個體通道項目的 id 屬性設定為這個樣板的 ref 屬性。

<configuration>

  <system.runtime.remoting> 項目

    <channels> 項目 (樣板)

      <channel> 項目 (樣板)

<channel  
   id="channelID" 
   type="ChannelType, ChannelAssembly"
   displayName="displayName"
   customChannelProperty="customChannelValue"
   <!-- Available only to client configurations -->
   delayLoadAsClientChannel="true|false"
/>

屬性和項目

下列章節將說明屬性、子項目和父項目。

屬性

屬性 說明

customChannelProperty

選擇性屬性。

指示支援的自訂通道屬性。您可以指定通道可能支援的任何通道屬性數量。自訂通道屬性可以是以屬性/值配組指定的。例如:

<channel id="CustomChannel" type="Namespace.CustomChannel, CustomChannels" customProperty="PropertyValue"/>

delayLoadAsClientChannel

選擇性屬性。

指示如果用戶端沒有為應用程式註冊通道,是否該載入這個通道。這個值為布林值,並且只會影響用戶端行為。true 值表示 .NET Framework 遠端處理應該在執行階段測試這個通道,檢查它是否支援用戶端連線 (其使用在遠端啟動過程 URL 中指定的特定通訊協定配置)。如果該值不存在,預設值為 false

displayName

選擇性屬性。

.NET Framework 組態工具用來建立這個應用程式所使用的通道清單。.NET Framework 遠端處理系統不使用這個屬性。

id

必要屬性。

提供應用程式用來識別在註冊位置之通道的字串。若要參考這個通道樣板,在執行個體通道項目中將這個屬性指定為 ref 屬性的值。

子項目

項目 說明

<serverProviders>

包含將插入伺服器端通道接收呼叫鏈結中的接收之接收提供者。如果有指定,這些會完全覆寫通道的預設值。這個項目可以在 <channel> 樣板項目中出現一次。

<clientProviders>

包含將插入用戶端通道接收呼叫鏈結中的接收之接收提供者。如果有指定,這些會完全覆寫通道的預設值。這個項目可以在 <channel> 樣板項目中出現一次。

父項目

項目 說明

channels

包含應用程式用來與遠端物件通訊的通道樣板。只要是已註冊通道的任何位置,就可以參考在此項目底下宣告的通道。

configuration

Common Language Runtime 和 .NET Framework 應用程式所使用之每個組態檔中的根項目。

system.runtime.remoting

指定 ASP.NET 組態區段的根項目。

備註

通道樣板可以存放在電腦組態檔、應用程式檔案或任何由呼叫 RemotingConfiguration.Configure() 所載入的其他檔案中。

範例

下列組態檔使用 <channels> 樣板項目來宣告具有 id "httpbinary" 的 HttpChannel,其使用 BinaryClientFormatterSink 來序列化遠端呼叫。然後它會要求這個用戶端應用程式藉由指定 <application> 項目內 <channel> 執行個體項目中的 ref="httpbinary",來使用該特定通道組態。最後,它會將 propsetter 通道接收提供者加入,並且傳遞一些將會由該通道接收提供者所使用的自訂組態項目。請注意,以任何方式使用 type 屬性指定組件 (在全域組件快取中) 的型別,需要有完整的型別資訊,包括版本、文化特性和公開金鑰資訊。在下面的 type 屬性中已將這項資訊省略,以求簡單扼要。

<configuration>
   <system.runtime.remoting>
      <channelSinkProviders>
         <clientProviders>
            <provider 
               id="propsetter" 
               type="ChannelSinkPropertySetterProvider, PropsSink" 
            />
         </clientProviders>
      <channels>
         <channel 
            type="System.Runtime.Remoting.Channels.Http.HttpChannel, System.Runtime.Remoting, ...." 
            id="httpbinary"
         >
            <clientProviders>
               <formatter                   type="System.Runtime.Remoting.Channels.BinaryClientFormatterSinkProvider, System.Runtime.Remoting, ...."
               />
            </clientProviders>
         </channel>
      </channels>
      <application>
         <channels>
            <channel ref="httpbinary">
               <clientProviders>
                  <provider 
                     ref="propsetter" 
                     username="somename" 
                     writeToConsole="true"
                  >
                     <endpoint url="contoso.com:9000" someProperty="xyz" />
                     <endpoint url="contoso.com:9001" someProperty="123" />
                  </provider>
               </clientProviders>
            </channel>
         </channels>
         <client>
            <wellknown 
               url="http://computername:80/RemoteType.rem"
               type="RemoteType, RemoteAssembly"
            />
         </client>
      </application>
   </system.runtime.remoting>
</configuration>

請參閱

參考

遠端設定結構描述
HttpChannel
HttpClientChannel
HttpServerChannel
TcpChannel
TcpClientChannel
TcpServerChannel

Footer image

Copyright © 2007 by Microsoft Corporation. All rights reserved.