共用方式為


新增接聽程式配接器新增 <>

概觀

<add><listenerAdapters> 元素會指定非 HTTP 接聽程式配接器的組態設定,此配接器可由 Windows Process Activation Service (WAS) 來與接聽程式服務通訊。

相容性

版本 備註
IIS 10.0 <add> IIS 10.0 中未修改專案。
IIS 8.5 <add> 在 IIS 8.5 中修改專案。
IIS 8.0 在 IIS 8.0 中未修改專案 <add>
IIS 7.5 <add> 在 IIS 7.5 中修改專案。
IIS 7.0 元素 <add><listenerAdapters> 元素是在 IIS 7.0 中引進。
IIS 6.0 N/A

安裝程式

元素 <add><listenerAdapters> 元素包含在 IIS 7 的預設安裝中。

作法

沒有用於新增 IIS 7 接聽程式配接器的使用者介面。 For examples of how to add listener adapters programmatically, see the Code Samples section of this document.

組態

屬性

屬性 描述
identity 選擇性字串屬性。

指定本機帳戶名稱、網域帳戶或內建帳戶。 身分識別可用來協助保護接聽程式服務與接聽程式配接器之間的 WAS 通道。
name 必要的字串屬性。

指定 WAS 連接接聽程式服務之接聽程式配接器的唯一名稱。
protocolManagerDll 選擇性字串屬性。

指定包含接聽程式配接器程式碼之 DLL 的完整路徑或簡短名稱。 您必須在磁片上找到 DLL (,方法是使用相依于 DLL 類型的標準搜尋程式) ,才能呼叫 protocolManagerDllInitFunction 中指定的函式。
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設定這些設定時,請務必將 認可 參數 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()