如何:在 IIS 中承载工作流服务
可以在 Internet 信息服务 (IIS) 中承载工作流服务,其方式与在 IIS 中承载 Windows Communication Foundation (WCF) 服务的方式大致相同,即通过使用服务和 Web 配置文件以及一些应用程序代码。 工作流服务由于是承载于 IIS 中,因而可利用 IIS 功能,如自动进程回收、进程运行状况监视等等。
在 IIS 中承载工作流服务有三种方法。 第一种方法是在 .svc 文件中引用预编译的工作流定义。 第二种方法是使用带有 .xoml 扩展名的工作流标记文件。 第三种方法是在 .svc 文件中引用一个工作流标记文件。
第二种方法在 .xoml 或 .rules 文件的更新上提供自动回收功能。 最后一个方法是为扩展性方案提供的,例如实现用于宿主工作流标记的自定义 WorkflowServiceHost。
备注
将工作流服务作为 App_Code 目录中的独立源文件中的代码进行部署时,或使用内联代码 ASP.NET 模型部署服务时,应该在 Web.config 文件中通过 <compilation> 配置元素引用工作流程序集,如下面的示例所示:
<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 中作为服务承载预编译的工作流定义
确认 IIS 已经安装并在计算机上运行。
为工作流服务创建一个新的虚拟目录并确保 ASP.NET 有权访问该目录。
创建一个新的带有 .svc 扩展名的服务文件。 编辑此文件,在其中为工作流服务添加适当的 ServiceHost 指令信息。 Factory 值必须引用 WorkflowServiceHostFactory 类。 下面的示例演示一个带有适当的值的服务文件。
<%@ServiceHost language=c# Debug="true" Service="Microsoft.WorkflowServices.Samples.StateMachineCalculatorService" Factory="System.ServiceModel.Activation.WorkflowServiceHostFactory" %>
在步骤 2 中创建的虚拟目录中创建一个 Bin 子目录。
将包含工作流服务类型的程序集放入 Bin 目录中。
在应用程序目录中创建一个名为 Web.config 的文件。 若要运行服务,Web.config 文件必须位于与服务文件相同的目录中。
在文件中添加相应的配置代码。 在运行时,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 中作为服务承载声明性工作流定义
确认 IIS 已经安装并在计算机上运行。
为工作流服务创建一个新的虚拟目录并确保 ASP.NET 有权访问该目录。
将工作流标记文件(带有扩展名 .xoml)和具有相同名称的可选规则文件(带有扩展名 .rules)放入虚拟目录中。
在应用程序目录中创建一个名为 Web.config 的文件。 若要运行服务,Web.config 文件必须位于与服务文件相同的目录中。
在文件中添加相应的配置代码。 在运行时,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 文件作为服务承载声明性工作流定义
确认 IIS 已经安装并在计算机上运行。
为工作流服务创建一个新的虚拟目录并确保 ASP.NET 有权访问该目录。
将工作流标记文件(带有扩展名 .xoml)和具有相同名称的可选规则文件(带有扩展名 .rules)放入虚拟目录中。
将带有下列标记的服务指令(带有扩展名 .svc)放入相同的目录中:
<%@ServiceHost language=c# Debug="true" Service="Calculator.xoml" Factory="System.ServiceModel.Activation.WorkflowServiceHostFactory" %>
在应用程序目录中创建一个名为 Web.config 的文件。若要运行服务,Web.config 文件必须位于与服务文件相同的目录中。
在文件中添加相应的配置代码。 在运行时,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>
请参见
其他资源
版权所有 (C) 2007 Microsoft Corporation。保留所有权利。