添加侦听器适配器 <add>

概述

<listenerAdapters><add> 元素指定了非 HTTP 侦听器适配器的配置设置,Windows Process Activation Service (WAS) 可以使用该适配器与侦听器服务进行通信。

兼容性

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

安装

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

操作方式

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

配置

特性

属性 说明
identity 可选的字符串属性。

指定本地帐户名称、域帐户或内置帐户。 标识用于帮助保护侦听器服务和侦听器适配器之间的 WAS 信道。
name 必需的字符串属性。

指定 WAS 连接侦听器服务的侦听器适配器的唯一名称。
protocolManagerDll 可选的字符串属性。

指定包含侦听器适配器代码的 DLL 的完全限定的路径或短名称。 若要调用 protocolManagerDllInitFunction 中指定的函数,必须在磁盘上找到 DLL(使用依赖于 DLL 类型的标准搜索过程)
protocolManagerDllInitFunction 可选的字符串属性。

指定要在自定义侦听器适配器代码中调用的函数的名称。 protocolManagerDll 属性中指定的 DLL 必须包含 protocolManagerDllInitFunction 属性中指定的函数

注意:此属性区分大小写;指定初始化函数的名称时,必须使用正确的大小写。

子元素

无。

配置示例

以下配置示例为 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()