Windows Process Activation Service (WAS) 是 IIS 7.0 核心元件,將啟動程序從 HTTP 綁定解耦,支援 TCP、Named Pipes、MSMQ 等非 HTTP 協定裝載 WCF 服務,同時保留 IIS 的進程管理、回收、健康監控等企業級特性。
| 元件 | IIS 6.0 | IIS 7.0 (WAS) |
|---|---|---|
| 監聽器 | w3svc (僅 HTTP) | w3svc (HTTP) + SMSvcHost.exe (TCP/Pipe/MSMQ) |
| 啟動管理 | w3svc 內建 | WAS (獨立 NT 服務) |
| 設定儲存 | Metabase (XML) | applicationHost.config |
| 非 HTTP 支援 | 無 | 原生支援 |
applicationHost.config 應用程式集區與站點設定。w3wp.exe),依需求啟動新實例。NetTcpActivator (在 SMSvcHost.exe) 向 WAS 註冊,取得應用程式位址與 Listener Channel ID。WebhostOpenListenerChannelInstance,傳遞 Channel ID 與資料 Blob (含應用程式鍵)。w3wp.exe → 載入 CLR (透過 aspnet_isapi.dll) → 建立預設 AppDomain。web.config 協定處理常設定 (如 net.tcp 對應 TcpProcessProtocolHandler)。IAdphManager 啟動應用程式專屬 AppDomain 與 AppDomain Protocol Handler (ADPH)。[ServiceContract] public interface IDemoService { string Ping(string data); }
public class DemoService : IDemoService { public string Ping(string d) => "pinged with: " + d; }
<% @ServiceHost Service="DemoService" %>
<system.serviceModel>
<services>
<service name="DemoService" behaviorConfiguration="Behavior">
<endpoint address="" binding="wsHttpBinding" contract="IDemoService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Behavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<site name="Default Web Site">
<bindings>
<binding protocol="http" bindingInformation="*:80:" />
<binding protocol="net.tcp" bindingInformation="808:*" />
<binding protocol="net.pipe" bindingInformation="*" />
<binding protocol="net.msmq" bindingInformation="localhost" />
</bindings>
<application path="/WasDemo" enabledProtocols="http,net.tcp,net.pipe,net.msmq">
<virtualDirectory path="/" physicalPath="C:\WasDemo" />
</application>
</site>
<endpoint address="" binding="netTcpBinding" contract="IDemoService" />
<endpoint address="" binding="netNamedPipeBinding" contract="IDemoService" />
<endpoint address="net.msmq://localhost/private/wasdemo/service.svc"
binding="netMsmqBinding" contract="IServiceMsmq" />
InstanceContextMode.PerCall 無狀態服務。ServiceHostFactoryBase 自訂 Factory 掛接 Opening/Closing 事件處理啟動/關閉邏輯。appcmd.exe、Microsoft.Web.Administration (ServerManager API)、PowerShell/WMI。