WF事件驱动(5)

之前,我通过4篇文章介绍了在WF4中开发基于事件的工作流的范例。请参考下面的链接。

 

这一篇是这个系列的最后一篇,介绍如何通过配置文件,而不是代码的方式启动宿主。这在现实工作中是相当有用的,请大家参考下面的实例。

【注意】有朋友也问到单独用数据库存储业务方面的数据,那是没有错的。一般可以通过自定义的Activity去完成这些操作,都是标准的ADO.NET的数据访问操作。这里就不做展开了。

 

这个案例的最终代码范例,请通过 这里 下载

1.修改之前的Host代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Activities;
using System.ServiceModel.Activities;
using System.ServiceModel.Description;using System.Activities.DurableInstancing;
using System.Runtime.DurableInstancing;
using System.Activities.Persistence;
using System.ServiceModel.Activities.Description;
using System.Xml.Linq;namespace Host
{class Program{static void Main(string[] args){var host = new WorkflowServiceHost(new DocumentReviewLib.DocumentReviewWorkflow(),new Uri("http://localhost:8080/DRS"));host.AddDefaultEndpoints();//这个方法是添加了一些标准的端点host.Description.Behaviors.Add(new ServiceMetadataBehavior() { HttpGetEnabled = true });var store = new SqlWorkflowInstanceStore("server=(local)\\sqlexpress;database=WF4;integrated security=true");host.UnknownMessageReceived += (o, e) =>{Console.WriteLine("\n" + e.Message + "\n");};host.Description.Behaviors.Add(new WorkflowIdleBehavior(){TimeToPersist = TimeSpan.FromSeconds(0)});XNamespace xNS = XNamespace.Get("http://xizhang.com/DocumentReview");store.Promote("DocumentReview",new List<XName>() { xNS.GetName("TicketId") },null);host.WorkflowExtensions.Add(new Extensions.MyInstanceStoreParticpant());host.DurableInstancingOptions.InstanceStore = store;host.Open();var common = new ServiceHost(typeof(CommonService),new Uri("http://localhost:8080/Common"));common.AddServiceEndpoint(typeof(ICommonService).FullName,new BasicHttpBinding(),"");common.Open();Console.WriteLine("Server is ready.");Console.Read();}}[ServiceContract]public interface ICommonService{[OperationContract]int[] GetTicketIds();}public class CommonService : ICommonService{public int[] GetTicketIds(){var ctx = new InstanceStoreDataContext();return ctx.DocumentReviewTasks.Select(r => (int)r.TicketId).ToArray();}}}

2. 修改之后的Host代码(请大家比较一下有何区别)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Activities;
using System.ServiceModel.Activities;
using System.ServiceModel.Description;using System.Activities.DurableInstancing;
using System.Runtime.DurableInstancing;
using System.Activities.Persistence;
using System.ServiceModel.Activities.Description;
using System.Xml.Linq;namespace Host
{class Program{static void Main(string[] args){var host = new WorkflowServiceHost(new WorkflowService() { ConfigurationName = "DocumentReviewLib.DocumentReviewWorkflow",Body = new DocumentReviewLib.DocumentReviewWorkflow()});//这里可以通过进一步的Behavior定制来简化。此处略            XNamespace xNS = XNamespace.Get("http://xizhang.com/DocumentReview");var store = (SqlWorkflowInstanceStoreBehavior)host.Description.Behaviors.FirstOrDefault(b => b.GetType() == typeof(SqlWorkflowInstanceStoreBehavior));store.Promote("DocumentReview",new List<XName>() { xNS.GetName("TicketId") },null);//这里可以通过进一步的Behavior定制来简化。此处略host.WorkflowExtensions.Add(new Extensions.MyInstanceStoreParticpant());host.Open();var common = new ServiceHost(typeof(CommonService));common.Open();Console.WriteLine("Server is ready.");Console.Read();}}[ServiceContract]public interface ICommonService{[OperationContract]int[] GetTicketIds();}public class CommonService : ICommonService{public int[] GetTicketIds(){var ctx = new InstanceStoreDataContext();return ctx.DocumentReviewTasks.Select(r => (int)r.TicketId).ToArray();}}}

3.添加的app.config文件内容

<?xml version="1.0" encoding="utf-8" ?>
<configuration><configSections></configSections><connectionStrings><add name="Host.Properties.Settings.WF4ConnectionString" connectionString="Data Source=.\sqlexpress;Initial Catalog=WF4;Integrated Security=True"providerName="System.Data.SqlClient" /></connectionStrings><system.serviceModel><behaviors><serviceBehaviors><behavior name="WorkflowService"><sqlWorkflowInstanceStore connectionStringName="Host.Properties.Settings.WF4ConnectionString"/><workflowIdle timeToPersist="0" timeToUnload="0"/><serviceMetadata httpGetEnabled="true"/></behavior></serviceBehaviors></behaviors><services><service name="DocumentReviewLib.DocumentReviewWorkflow" behaviorConfiguration="WorkflowService"><host><baseAddresses><add baseAddress="http://localhost:8080/DRS"/></baseAddresses></host><endpoint contract="IDocumentReview" address="" binding="basicHttpBinding"></endpoint></service><service name="Host.CommonService"><host><baseAddresses><add baseAddress="http://localhost:8080/Common"/></baseAddresses></host><endpoint contract="Host.ICommonService" binding="basicHttpBinding" address=""></endpoint></service></services></system.serviceModel></configuration>
 
这个案例的最终代码范例,请通过  下载

转载于:https://www.cnblogs.com/Mayvar/archive/2011/09/03/wanghonghua201109030455.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/380263.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

合页损失,铰链损失_多点铰链损失功能 使用Python的线性代数

合页损失,铰链损失Hinge Loss is a loss function used in Machine Learning for training classifiers. The hinge loss is a maximum margin classification loss function and a major part of the SVM algorithm. 铰链损失是机器学习中用于训练分类器的损失函数。 铰链损失…

远控免杀专题8---BackDoor-Facktory免杀

0x01 免杀能力一查表 几点说明&#xff1a; 1、上表中标识 √ 说明相应杀毒软件未检测出病毒&#xff0c;也就是代表了Bypass。 2、为了更好的对比效果&#xff0c;大部分测试payload均使用msf的windows/meterperter/reverse_tcp模块生成。 3、由于本机测试时只是安装了360全…

Visual Studio 2010旗舰版在安装Windows Phone 7 SDK后项目模版里没有Windows Phone 项目解决办法...

这个方法解决安装Windows Phone Develop Tools自带的Visual Studio 2010 Express for Windows Phone后&#xff0c;在已安装的Visual Studio 2010旗舰版中没有Windows Phone 7项目的情况。 1.找到Express版的模板&#xff0c;通常在&#xff1a; C:\Program Files (x86)\Micros…

不用ajax实现动态分页,详解ajax +jtemplate实现动态分页

jtemplate是一个基于JQuery的模板引擎插件&#xff0c;功能非常强大&#xff0c;有了她你就再不用为使用JS绑定数据集而发愁了。主要思路&#xff0c;复制textarea作为模板&#xff0c;ajax加载json数据&#xff0c;添加模板&#xff0c;绑定数据&#xff0c;更新加载更多事件。…

程序员每天每周每月每年该做的事

1、总结自己一天任务的完成情况  最好的方式是写工作日志&#xff0c;把自己今天完成了什么事情&#xff0c;遇见了什么问题都记录下来&#xff0c;日后翻看好处多多。 2、考虑自己明天应该做的主要工作  把明天要做的事情列出来&#xff0c;并按照优先级排列&#xff0c;第…

C和汇编----存储类别、链接和内存管理

0x01 存储类别 1、作用域 一个C变量的作用域可以是块作用域、函数作用域、函数原型作用域或文件作用域。 1.1 块作用域&#xff1a; 块是用一对花括号括起来的代码区域。比如函数体就是一个块。定义在块中的变量具有块作用域&#xff0c;块作用域变量的可见范围是从定义处到包…

倒三角(随即输入)

package wsq; import java.util.*; public class wsqyy {public static void main(String[] args) {Scanner wsqnew Scanner(System.in);int xwsq.nextInt();int i,j,k;for(i0;i<x;i)//第一个for循环控制行数&#xff1b;{for(j0;j<i;j)//第二个for循环控制输出&#xff…

调用向量的第i维分量| 使用Python的线性代数

Prerequisite: Linear Algebra | Defining a Vector 先决条件&#xff1a; 线性代数| 定义向量 Linear algebra is the branch of mathematics concerning linear equations by using vector spaces and through matrices. In other words, a vector is a matrix in n-dimensi…

EYQiPa,梦开始的地方

早在2003年&#xff0c;就有EYQiPa的设想&#xff0c;曾经尝试过去做它&#xff0c;不过总是不了了之。也许是当时技术能力不达标&#xff0c;也许是一直以来的对待事物缺少持之以恒的心态&#xff0c;时光如水&#xff0c;转眼8年过去了&#xff0c;这8年当中&#xff0c;总是…

结合struts和hibernate谈J2EE架构的数据表示

结合struts和hibernate谈J2EE架构的数据表示 在 struts hibernate 这种结构中&#xff0c;是不应该把Hibernate产生的PO直接传递给JSP的&#xff0c;不管他是Iterator&#xff0c;还是List&#xff0c;这是一个设计错误。 我来谈谈在J2EE架构中各层的数据表示方法&#xff1a;…

服务器appcrash的问题怎么修复,ghost win7出现appcrash的问题怎么修复

ghost win7出现appcrash的问题怎么修复一位用户说在win7旗舰版电脑中运行程序会出现appcrash错误的提示&#xff0c;appcrash出错想必很多用户都遇到过&#xff0c;也不知道什么原因引起的&#xff0c;导致程序无法正常运行。那么有什么方法可以解决ghost系统win7运行程序出现a…

远控免杀专题9 --- Avet免杀

0x01 免杀能力一查表 几点说明&#xff1a; 1、上表中标识 √ 说明相应杀毒软件未检测出病毒&#xff0c;也就是代表了Bypass。 2、为了更好的对比效果&#xff0c;大部分测试payload均使用msf的windows/meterperter/reverse_tcp模块生成。 3、由于本机测试时只是安装了360全…

字符串startswith_JavaScript字符串startsWith()方法与示例

字符串startswith字符串startsWith()方法 (String startsWith() Method) startsWith() method is a string method in JavaScript, it is used to check whether a string starts with a specified substring or not. startsWith()方法是JavaScript中的字符串方法&#xff0c;用…

方法:求两个数之和 判断两数是否相等

package wsq; import java.util.Scanner; public class wsq { public static void main(String[] args) { double a,b; Scanner wsqnew Scanner(System.in); awsq.nextDouble(); bwsq.nextDouble(); double cadd(a,b); System.out.println(“两数之和为&#xff1a;”…

WF随笔系列之三 --- Code Activity 专题

系列目录&#xff1a;WF随笔系列之三 Out-of-the-Box Activities 专题目录 Code Activity是WF开发中使用最频繁的Activity之一&#xff0c;它要做工作的很简单&#xff0c;就是把一个或者几个Code Exec 一下&#xff0c;当此行为在执行时&#xff0c;触发一个Handlers:Execute…

是知当代之士、驰骛之曹,书读纵横,则思诸侯之变

看到《职来职往》的智联招聘张勇为应聘者设计的一个问题&#xff0c;很有深度&#xff0c;值得借鉴&#xff1a; 是知当代之士、驰骛之曹&#xff0c;书读纵横&#xff0c;则思诸侯之变&#xff1b; 出自原文&#xff1a; 匠成舆者&#xff0c;忧人不贵&#xff1b; 作箭者&…

A5流密码算法

0x01 A5/1流密码算法的基本用法 作用&#xff1a; 用于蜂窝式移动电话系统语言和数字加密 过程&#xff1a; A5/1算法用于用户的手机到基站之间的通信加密&#xff0c;通信内容到基站后先解密变成明文&#xff0c;然后再进行基站到基站之间&#xff0c;以及基站到用户手机之间…

mcq 队列_MCQ | 密码学中作为IDEA,DES,AES,RSA的块密码

mcq 队列1) In the AES-128 algorithm there are mainly __________ similar rounds and _________ round is different from other round. 1)在AES-128算法中&#xff0c;主要有__________个相似的回合&#xff0c;而_________个回合与其他回合不同。 5 similar rounds havin…

Cookie存取和IE页面缓存的问题

最近老是发现在IE里会有Cookie的问题&#xff0c;如IE下面无法登出&#xff0c;或无法登录&#xff0c;或者登录后信息却无法取到&#xff0c;而Firefox下面一直是通过的&#xff0c;都试过好多次了&#xff0c;今天终于找回的主要的原因&#xff1b;Cookie的问题&#xff1a;首…

数组(一维、二维)

1&#xff0c; 动态初始化&#xff1a; int [] arr new int [5] 如果直接输出arr&#xff1b; System.out.print&#xff08;arr&#xff09;&#xff1b; 结果为&#xff1a; [I13b64eb [&#xff1a;表示一维数组&#xff0c;几个就代表几维数组&#xff1b; I&#xff1a;表…