配置 Windows 进程激活服务以用于 Windows Communication Foundation

本主题介绍在 Windows Vista 中设置 Windows 进程激活服务(也称为 WAS)使其承载不通过 HTTP 网络协议进行通信的 Windows Communication Foundation (WCF) 服务所需的步骤。下面的部分略述此配置的步骤:

  • 安装(或确认安装)所需的 WCF 激活组件。
  • 创建一个具有要使用的网络协议绑定的 WAS 站点,或者向现有站点添加新协议绑定。
  • 创建一个应用程序以承载服务,并使该应用程序可以使用所需的网络协议。
  • 生成一个公开非 HTTP 终结点的 WCF 服务。

使用非 HTTP 绑定配置站点

若要将非 HTTP 绑定与 WAS 一起使用,必须将站点绑定添加到 WAS 配置。WAS 的配置存储是 applicationHost.config 文件,该文件位于 %windir%\system32\inetsrv\config 目录中。此配置存储由 WAS 和 IIS 7.0 共享。

applicationHost.config 是一个 XML 文本文件,可以使用任何标准文本编辑器(如记事本)打开。不过,IIS 7.0 命令行配置工具 (appcmd.exe) 是添加非 HTTP 站点绑定的首选方法。

下面的命令使用 appcmd.exe 将 net.tcp 站点绑定添加到默认网站(将此命令作为单独的一行输入)。

appcmd.exe set site "Default Web Site" -+bindings.[protocol='net.tcp',bindingInformation='808:*']

通过将下面指示的行添加到 applicationHost.config 文件,此命令将新 net.tcp 绑定添加到默认网站。

<sites>
    <site name="Default Web Site" id="1">
        <bindings>
            <binding protocol="HTTP" bindingInformation="*:80:" />
            //The following line is added by the command.
            <binding protocol="net.tcp" bindingInformation="808:*" />
        </bindings>
    </site>
</sites>

使应用程序可以使用非 HTTP 协议

可以在应用程序级别上启用或禁用单个网络协议。下面的命令说明如何为在 Default Web Site 中运行的应用程序同时启用 HTTP 和 net.tcp 协议。

appcmd.exe set app "Default Web Site/appOne" /enabledProtocols:net.tcp

也可以在 ApplicationHost.config 中存储的站点 XML 配置的 <applicationDefaults> 元素中设置已启用协议列表。

摘自 applicationHost.config 的以下 XML 代码说明一个已同时绑定到 HTTP 协议和非 HTTP 协议的站点。支持非 HTTP 协议所需的其他配置通过注释进行了突出。

<sites>
    <site name="Default Web Site" id="1">
    <application path="/">
        <virtualDirectory path="/" physicalPath="D:\inetpub\wwwroot" />
    </application>
       <bindings>
            //The following two lines are added by the command.
            <binding protocol="HTTP" bindingInformation="*:80:" />
            <binding protocol="net.tcp" bindingInformation="808:*" />
       </bindings>
    </site>
    <siteDefaults>
        <logFile 
        customLogPluginClsid="{FF160663-DE82-11CF-BC0A-00AA006111E0}"
          directory="D:\inetpub\logs\LogFiles" />
        <traceFailedRequestsLogging 
          directory="D:\inetpub\logs\FailedReqLogFiles" />
    </siteDefaults>
    <applicationDefaults 
      applicationPool="DefaultAppPool" 
      //The following line is inserted by the command.
      enabledProtocols="http, net.tcp" />
    <virtualDirectoryDefaults allowSubDirConfig="true" />
</sites>

生成一个将 WAS 用于非 HTTP 激活的 WCF 服务

执行安装和配置 WAS 的步骤后(如前所述),将服务配置为使用 WAS 进行激活与配置承载于 IIS 中的服务类似。

有关生成 WAS 激活的 WCF 服务的详细说明,请参见如何:在 WAS 中承载 WCF 服务

另请参见

概念

在 Windows 进程激活服务中承载