侦听器适配器 <listenerAdapters>

概述

<listenerAdapters> 元素指定 Internet Information Services (IIS) 7 侦听器适配器的配置设置。 侦听器适配器是在非 HTTP 协议侦听器服务与 Windows 进程激活服务 (WAS) 之间建立通信的组件。 仅当侦听器适配器与 WAS 连接时,对 <listenerAdapters> 元素的更改才会生效。 在大多数情况下,此连接要求重启服务器。

注意:

  • World Wide Web 发布服务 (W3SVC) 包含用于 IIS 7 的 HTTP 特定功能,因此不使用额外的 <listenerAdapters> 属性。 - 不需要 WAS 的 FTP 服务没有 <listenerAdapters> 条目。

兼容性

版本 说明
IIS 10.0 <listenerAdapters> 元素在 IIS 10.0 中未进行修改。
IIS 8.5 <listenerAdapters> 元素在 IIS 8.5 中未进行修改。
IIS 8.0 <listenerAdapters> 元素在 IIS 8.0 中未进行修改。
IIS 7.5 <listenerAdapters> 元素在 IIS 7.5 中未进行修改。
IIS 7.0 <listenerAdapters> 元素是在 IIS 7.0 中引入的。
IIS 6.0 空值

安装

<listenerAdapters> 元素包含在 IIS 7 的默认安装中。

操作方式

IIS 7 中没有用于添加侦听器适配器的用户界面。 有关如何以编程方式添加侦听器适配器的示例,请参阅本文档的代码示例部分。

配置

特性

无。

子元素

元素 说明
add 可选元素。

指定侦听器适配器的配置。

配置示例

以下配置示例为 Gopher 协议提供程序添加了侦听器适配器,并指定了 DLL 的名称及其初始化函数。

<system.applicationHost>
   <listenerAdapters>
      <add name="gopher"
         protocolManagerDll="%SystemRoot%\system32\inetsrv\gophersvc.dll"
         protocolManagerDllInitFunction="GopherInit" />
   </listenerAdapters>
</system.applicationHost>

代码示例

以下代码示例为 Gopher 协议提供程序添加了侦听器适配器,并指定了 DLL 的名称及其初始化函数。

AppCmd.exe

appcmd.exe set config -section:system.applicationHost/listenerAdapters /+"[name='gopher',protocolManagerDll='%SystemRoot%\system32\inetsrv\gophersvc.dll',protocolManagerDllInitFunction='GopherInit']" /commit:apphost

注意

使用 AppCmd.exe 配置这些设置时,必须确保将 commit 参数设置为 apphost。 这会将配置设置提交到 ApplicationHost.config 文件中的相应位置部分。

C#

using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample
{
   private static void Main()
   {
      using (ServerManager serverManager = new ServerManager())
      {
         Configuration config = serverManager.GetApplicationHostConfiguration();
         ConfigurationSection listenerAdaptersSection = config.GetSection("system.applicationHost/listenerAdapters");
         ConfigurationElementCollection listenerAdaptersCollection = listenerAdaptersSection.GetCollection();

         ConfigurationElement addElement = listenerAdaptersCollection.CreateElement("add");
         addElement["name"] = @"gopher";
         addElement["protocolManagerDll"] = @"%SystemRoot%\system32\inetsrv\gophersvc.dll";
         addElement["protocolManagerDllInitFunction"] = @"GopherInit";
         listenerAdaptersCollection.Add(addElement);

         serverManager.CommitChanges();
      }
   }
}

VB.NET

Imports System
Imports System.Text
Imports Microsoft.Web.Administration

Module Sample

   Sub Main()
      Dim serverManager As ServerManager = New ServerManager
      Dim config As Configuration = serverManager.GetApplicationHostConfiguration
      Dim listenerAdaptersSection As ConfigurationSection = config.GetSection("system.applicationHost/listenerAdapters")
      Dim listenerAdaptersCollection As ConfigurationElementCollection = listenerAdaptersSection.GetCollection

      Dim addElement As ConfigurationElement = listenerAdaptersCollection.CreateElement("add")
      addElement("name") = "gopher"
      addElement("protocolManagerDll") = "%SystemRoot%\system32\inetsrv\gophersvc.dll"
      addElement("protocolManagerDllInitFunction") = "GopherInit"
      listenerAdaptersCollection.Add(addElement)

      serverManager.CommitChanges()
   End Sub

End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var listenerAdaptersSection = adminManager.GetAdminSection("system.applicationHost/listenerAdapters", "MACHINE/WEBROOT/APPHOST");
var listenerAdaptersCollection = listenerAdaptersSection.Collection;

var addElement = listenerAdaptersCollection.CreateNewElement("add");
addElement.Properties.Item("name").Value = "gopher";
addElement.Properties.Item("protocolManagerDll").Value = "%SystemRoot%\\system32\\inetsrv\\gophersvc.dll";
addElement.Properties.Item("protocolManagerDllInitFunction").Value = "GopherInit";
listenerAdaptersCollection.AddElement(addElement);

adminManager.CommitChanges();

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set listenerAdaptersSection = adminManager.GetAdminSection("system.applicationHost/listenerAdapters", "MACHINE/WEBROOT/APPHOST")
Set listenerAdaptersCollection = listenerAdaptersSection.Collection

Set addElement = listenerAdaptersCollection.CreateNewElement("add")
addElement.Properties.Item("name").Value = "gopher"
addElement.Properties.Item("protocolManagerDll").Value = "%SystemRoot%\system32\inetsrv\gophersvc.dll"
addElement.Properties.Item("protocolManagerDllInitFunction").Value = "GopherInit"
listenerAdaptersCollection.AddElement(addElement)

adminManager.CommitChanges()