共用方式為


HOW TO:在 IIS 中裝載工作流程服務

工作流程服務可裝載在網際網路資訊服務 (IIS) 中,其裝載方式與將 Windows Communication Foundation (WCF) 服務裝載在 IIS 中幾乎相同,即透過使用服務和 Web 組態檔以及一些應用程式碼來裝載。 裝載在 IIS 中可讓工作流程服務利用 IIS 功能,例如自動處理回收、處理健康監視等等。

有三個方法可將工作流程服務裝載在 IIS 中。 第一個方法是參考 .svc 檔中先行編譯的工作流程定義。 第二個方法是使用副檔名為 .xoml 的工作流程標記檔案。 第三個方法是參考 .svc 檔案中的工作流程標記檔案。

第二個方法在更新至 .xoml 或 .rules 檔時,會提供自動回收功能。 最後一個方法是為擴充性案例所提供,如實作自訂 WorkflowServiceHost 以裝載工作流程標記。

注意

在 App_Code 目錄內獨立原始程式檔中將工作流程服務部署為程式碼,或使用程式碼內嵌 ASP.NET 模型部署服務時,您應透過 <compilation> 組態項目來參考 Web.config 檔中的工作流程組件,如下列範例所示:

<system.web>
    <compilation>
      <assemblies>
        <add assembly="System.Workflow.Activities, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        <add assembly="System.Workflow.ComponentModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        <add assembly="System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      </assemblies>
    </compilation>
  </system.web>

注意

在 IIS 中裝載程式碼內嵌工作流程時,不會使用工作流程編譯器。 只會使用語言特定編譯器,例如 C# 編譯器。

在 IIS 中將預先編譯的工作流程定義裝載為服務

  1. 確認您的電腦上已安裝 IIS 且正在執行中。

  2. 為您的工作流程服務建立新的虛擬目錄,並確定 ASP.NET 有存取權。

  3. 建立副檔名為 .svc 的新服務檔案。 新增工作流程服務的適當 ServiceHost 指示詞資訊來編輯這個檔案。 Factory 值必須參考 WorkflowServiceHostFactory 類別。 下列範例顯示服務檔案及適當的值。

    <%@ServiceHost language=c# Debug="true" Service="Microsoft.WorkflowServices.Samples.StateMachineCalculatorService" Factory="System.ServiceModel.Activation.WorkflowServiceHostFactory" %>
    
  4. 在步驟 2 中建立的虛擬目錄內建立 Bin 子目錄。

  5. 將包含您工作流程服務型別的組件置於 Bin 目錄中。

  6. 在應用程式目錄中建立名為 Web.config 的檔案。 若要執行服務,Web.config 檔必須位於與服務檔相同的目錄中。

  7. 在檔案中新增適當的組態程式碼。 在執行階段,WCF 基礎結構會使用這項資訊以建構用戶端應用程式可通訊的端點。 若為 StateMachineCalculatorService 範例,組態程式碼如下:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    
      <system.serviceModel>
        <services>
          <service name="Microsoft.WorkflowServices.Samples.StateMachineCalculatorService" behaviorConfiguration="ServiceBehavior" >
            <endpoint address="" 
                      binding="customBinding"
                      bindingConfiguration="basicHttpCookieBinding"
                      contract="Microsoft.WorkflowServices.Samples.ICalculator" />
            <endpoint address="ContextOverHttp" 
                      binding="wsHttpContextBinding" 
                      contract="Microsoft.WorkflowServices.Samples.ICalculator" />
          </service>
        </services>
    
        <behaviors>
          <serviceBehaviors>
            <behavior name="ServiceBehavior"  >
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
              <serviceCredentials>
                <windowsAuthentication
                    allowAnonymousLogons="false"
                    includeWindowsGroups="true" />
              </serviceCredentials>
              <!-- Comment out the following behavior to disable persistence store -->
              <workflowRuntime name="WorkflowServiceHostRuntime" validateOnCreate="true" enablePerformanceCounters="true">
                <services>
                  <add type="System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                       connectionString="Data Source=localhost\sqlexpress;Initial Catalog=NetFx35Samples_ServiceWorkflowStore;Integrated Security=True;Pooling=False"
                       LoadIntervalSeconds="1" UnLoadOnIdle= "true" />
                </services>
              </workflowRuntime>
            </behavior>
          </serviceBehaviors>
        </behaviors>
    
        <bindings>
          <customBinding>
            <binding name="basicHttpCookieBinding">
              <context contextExchangeMechanism="HttpCookie" />
              <textMessageEncoding messageVersion="Soap11" />
              <httpTransport authenticationScheme="Ntlm" />
            </binding>
          </customBinding>
        </bindings>
    
      </system.serviceModel>
    
      <system.web>
        <compilation>
          <assemblies>
            <add assembly="System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
          </assemblies>
        </compilation>
      </system.web>
    
    </configuration>
    

在 IIS 中將宣告式工作流程定義裝載為服務

  1. 確認您的電腦上已安裝 IIS 且正在執行中。

  2. 為您的工作流程服務建立新的虛擬目錄,並確定 ASP.NET 有存取權。

  3. 將工作流程標記檔案 (副檔名 .xoml) 和檔名相同 (副檔名 .rules) 的選擇性規則標記檔案置於虛擬目錄中。

  4. 在應用程式目錄中建立名為 Web.config 的檔案。 若要執行服務,Web.config 檔必須位於與服務檔相同的目錄中。

  5. 在檔案中新增適當的組態程式碼。 在執行階段,WCF 基礎結構會使用這項資訊以建構用戶端應用程式可通訊的端點。 若為 StateMachineCalculatorService 範例,組態程式碼如下:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    
      <system.serviceModel>
        <services>
    <!-- Service name is workflow Name -->
          <service name="StateMachineCalculatorService" behaviorConfiguration="ServiceBehavior" >
            <endpoint address="" 
                      binding="customBinding"
                      bindingConfiguration="basicHttpCookieBinding"
                      contract="Microsoft.WorkflowServices.Samples.ICalculator" />
            <endpoint address="ContextOverHttp" 
                      binding="wsHttpContextBinding" 
                      contract="Microsoft.WorkflowServices.Samples.ICalculator" />
          </service>
        </services>
    
        <behaviors>
          <serviceBehaviors>
            <behavior name="ServiceBehavior"  >
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
              <serviceCredentials>
                <windowsAuthentication
                    allowAnonymousLogons="false"
                    includeWindowsGroups="true" />
              </serviceCredentials>
              <!-- Comment out the following behavior to disable persistence store -->
              <workflowRuntime name="WorkflowServiceHostRuntime" validateOnCreate="true" enablePerformanceCounters="true">
                <services>
                  <add type="System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                       connectionString="Data Source=localhost\sqlexpress;Initial Catalog=NetFx35Samples_ServiceWorkflowStore;Integrated Security=True;Pooling=False"
                       LoadIntervalSeconds="1" UnLoadOnIdle= "true" />
                </services>
              </workflowRuntime>
            </behavior>
          </serviceBehaviors>
        </behaviors>
    
        <bindings>
          <customBinding>
            <binding name="basicHttpCookieBinding">
              <context contextExchangeMechanism="HttpCookie" />
              <textMessageEncoding messageVersion="Soap11" />
              <httpTransport authenticationScheme="Ntlm" />
            </binding>
          </customBinding>
        </bindings>
    
      </system.serviceModel>
    
      <system.web>
        <compilation>
          <assemblies>
            <add assembly="System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
          </assemblies>
        </compilation>
      </system.web>
    
    </configuration>
    

注意

工作流程標記檔案將成為工作流程服務其基底位址的一部分。 例如,基底位址可能如下所示:

http://servername:port/workflowmarkupfile.xoml/

以 .svc 檔案將宣告式工作流程定義裝載為服務

  1. 確認您的電腦上已安裝 IIS 且正在執行中。

  2. 為您的工作流程服務建立新的虛擬目錄,並確定 ASP.NET 有存取權。

  3. 將工作流程標記檔案 (副檔名 .xoml) 和檔名相同 (副檔名 .rules) 的選擇性規則標記檔案置於虛擬目錄中。

  4. 將服務指示詞 (副檔名 .svc) 與下列標記置於同一個目錄中:

    <%@ServiceHost language=c# Debug="true" Service="Calculator.xoml" Factory="System.ServiceModel.Activation.WorkflowServiceHostFactory" %>
    
  5. 在應用程式目錄中建立名為 Web.config 的檔案 - 若要執行服務,Web.config 檔必須位於與服務檔相同的目錄中。

  6. 在檔案中新增適當的組態程式碼。 在執行階段,WCF 基礎結構會使用這項資訊以建構用戶端應用程式可通訊的端點。 若為 StateMachineCalculatorService 範例,組態程式碼如下:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    
      <system.serviceModel>
        <services>
    <!-- Service name is workflow Name -->
          <service name="StateMachineCalculatorService" behaviorConfiguration="ServiceBehavior" >
            <endpoint address="" 
                      binding="customBinding"
                      bindingConfiguration="basicHttpCookieBinding"
                      contract="Microsoft.WorkflowServices.Samples.ICalculator" />
            <endpoint address="ContextOverHttp" 
                      binding="wsHttpContextBinding" 
                      contract="Microsoft.WorkflowServices.Samples.ICalculator" />
          </service>
        </services>
    
        <behaviors>
          <serviceBehaviors>
            <behavior name="ServiceBehavior"  >
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
              <serviceCredentials>
                <windowsAuthentication
                    allowAnonymousLogons="false"
                    includeWindowsGroups="true" />
              </serviceCredentials>
              <!-- Comment out the following behavior to disable persistence store -->
              <workflowRuntime name="WorkflowServiceHostRuntime" validateOnCreate="true" enablePerformanceCounters="true">
                <services>
                  <add type="System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                       connectionString="Data Source=localhost\sqlexpress;Initial Catalog=NetFx35Samples_ServiceWorkflowStore;Integrated Security=True;Pooling=False"
                       LoadIntervalSeconds="1" UnLoadOnIdle= "true" />
                </services>
              </workflowRuntime>
            </behavior>
          </serviceBehaviors>
        </behaviors>
    
        <bindings>
          <customBinding>
            <binding name="basicHttpCookieBinding">
              <context contextExchangeMechanism="HttpCookie" />
              <textMessageEncoding messageVersion="Soap11" />
              <httpTransport authenticationScheme="Ntlm" />
            </binding>
          </customBinding>
        </bindings>
    
      </system.serviceModel>
    
      <system.web>
        <compilation>
          <assemblies>
            <add assembly="System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
          </assemblies>
        </compilation>
      </system.web>
    
    </configuration>
    

請參閱

其他資源

建立工作流程服務和長期服務

Footer image

Copyright © 2007 by Microsoft Corporation. All rights reserved.