<clientProviders> 元素(实例)

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

包含信道接收器提供程序,当在配置文件中的其他位置引用此信道模板时,这些提供程序将成为该模板的默认客户端信道接收器调用链的一部分。在以下任一位置指定提供程序会重写此信道的默认信道接收器;如果希望将这些默认信道接收器中的任何一个插入到此模板的信道接收器调用链中,也必须在此处指定它们。

<configuration>

<system.runtime.remoting>

<channels>

<channel>

<clientProviders>

无论在何处引用此信道模板,此处的提供程序都会重写此信道的默认提供程序。

<configuration>

<system.runtime.remoting>

<application>

<channels>

<channel>

<clientProviders>

此处的提供程序只重写此信道实例的默认提供程序。

<clientProviders> 
      <formatter/> 
      <provider/> 
</clientProviders>

子元素

元素 说明

<formatter>

包含要插入到信道接收器调用链中的格式化程序接收器。可在 <clientProviders> 实例元素中出现一次。

<provider>

包含要插入到信道接收器调用链中的信道接收器。可在 <clientProviders> 实例元素中出现一次或多次。

备注

当在信道模板元素中使用时,在该级别显示的任何引用或声明的提供程序都将重写信道的默认提供程序,而且如果在配置文件中的其他地方引用该信道,则这些提供程序将成为默认提供程序。在使用此元素时会重写此信道的所有默认提供程序或格式化程序,认识到这一点很重要。如果希望除了任何自定义提供程序外,这些提供程序或格式化程序也成为此信道模板的一部分,则必须在其他信道引用该信道模板时,指定要与此信道一起使用的所有提供程序和格式化程序。

当在信道实例中使用时,在所显示的级别引用或声明的任何提供程序都将只为此信道实例重写此信道的默认提供程序。如果此实例引用声明 clientProviders 的模板,则在此处指示的提供程序也将完全重写这些默认提供程序。

示例

下面的配置文件使用 <channels> 模板元素声明 id 为“httpbinary”的 HttpChannel,并使用 <clientProviders> 模板元素指定 BinaryClientFormatterSink 以序列化远程调用。然后通过在 <application> 元素内的 <channel> 实例元素中指定 ref="httpbinary",请求此客户端应用程序使用该特定的信道配置。最后,它使用 <clientProviders> 实例元素添加“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" someProp="xyz" />
                     <endpoint url="contoso.com:9001" someProp="123" />
                  </provider>
               </clientProviders>
            </channel>
         </channels>
         <client>
            <wellknown 
               url="http://computername:80/RemoteType.rem"                type="RemoteType, RemoteAssembly"
            />
         </client>
      </application>
   </system.runtime.remoting>
</configuration>

要求

**配置文件:**应用程序配置文件、计算机配置文件 (Machine.config)

另请参见

参考

远程处理设置架构

概念

接收器和接收器链

生成日期:2010-02-13