Share via


<channel> 元素(模板)

本主题介绍一项传统技术,保留该技术是为了向后兼容现有的应用程序,不建议对新的开发使用该技术。现在应该使用  Windows Communication Foundation (WCF) 来开发分布式应用程序。

包含某信道模板,应用程序可指定并配置该信道模板,以便与远程对象进行通信或侦听对远程对象的请求。在可以注册信道以供使用的任何位置,都可以将该实例信道元素的 id 特性设置为此模板的 ref 特性。此元素可能出现在应用程序配置文件和计算机配置文件中。

Schema Hierarchy

<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

公共语言运行时和 .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

生成日期:2010-02-13