1. 创建一个空白的项目,在其中创建Host – Windows Console Application,Client – Windows forms Application和DataExchangeWorkflows – Activity Library这三个项目。创建后应该结构类似于下图:

2. 将工作流DataExchangeActivity.xaml设计为如下样式:

有几点需要注意:

1) 第一个Receive Activity的CanCreateInstance必须为True,否则客户端调用此Receive无法生成实例(一个工作流只需要第一个的CanCreateInstance为True)

2) TicketId变量保存生成的工作流示例编号,在后面更新时客户端将根据TicketId来更新状态。

3) _handler的类型是CorrelationHandle。_handler的作用是根据客户端发送过来的TicketId,搜索相匹配的工作流的TicketId。

4) 刚才说过,_handler是用于搜索相匹配的工作流的TicketId,在第二个Receive Activity「CheckCredit」的ServiceContractName不能为空白,否则在设置CorrelationOn的属性的时候,选择Id属性会报”ServiceContractName and OperationName properties of activity ‘Receive’ must be set in order to generate XPath”这个错。

5) 需要设置三个Arguments,用于传递Receive Activity「CheckCredit」的参数。

6) 最后生成的XML如下:

 <Activity mc:Ignorable="sap sap2010 sads" x:Class="DataExchangeWorkflows.DataExchangeActivity"

  xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"

  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

  xmlns:mca="clr-namespace:Microsoft.CSharp.Activities;assembly=System.Activities"

  xmlns:p="http://schemas.microsoft.com/netfx/2009/xaml/servicemodel"

  xmlns:sads="http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger"

  xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation"

  xmlns:sap2010="http://schemas.microsoft.com/netfx/2010/xaml/activities/presentation"

  xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib"

  xmlns:sco="clr-namespace:System.Collections.ObjectModel;assembly=mscorlib"

  xmlns:ssx="clr-namespace:System.ServiceModel.XamlIntegration;assembly=System.ServiceModel"

  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

   <x:Members>

     <x:Property Name="action" Type="InArgument(x:String)" />

     <x:Property Name="reviewId" Type="InArgument(x:Int32)" />

     <x:Property Name="comment" Type="InArgument(x:String)" />

   </x:Members>

   <sap2010:ExpressionActivityEditor.ExpressionActivityEditor>C#</sap2010:ExpressionActivityEditor.ExpressionActivityEditor>

   <sap2010:WorkflowViewState.IdRef>DataExchangeWorkflows.DataExchangeActivity_1</sap2010:WorkflowViewState.IdRef>

   <TextExpression.NamespacesForImplementation>

     <sco:Collection x:TypeArguments="x:String">

       <x:String>System</x:String>

       <x:String>System.Collections.Generic</x:String>

       <x:String>System.Data</x:String>

       <x:String>System.Linq</x:String>

       <x:String>System.Text</x:String>

       <x:String>System.ServiceModel.Activities</x:String>

     </sco:Collection>

   </TextExpression.NamespacesForImplementation>

   <TextExpression.ReferencesForImplementation>

     <sco:Collection x:TypeArguments="AssemblyReference">

       <AssemblyReference>Microsoft.CSharp</AssemblyReference>

       <AssemblyReference>System</AssemblyReference>

       <AssemblyReference>System.Activities</AssemblyReference>

       <AssemblyReference>System.Core</AssemblyReference>

       <AssemblyReference>System.Data</AssemblyReference>

       <AssemblyReference>System.Runtime.Serialization</AssemblyReference>

       <AssemblyReference>System.ServiceModel</AssemblyReference>

       <AssemblyReference>System.ServiceModel.Activities</AssemblyReference>

       <AssemblyReference>System.Xaml</AssemblyReference>

       <AssemblyReference>System.Xml</AssemblyReference>

       <AssemblyReference>System.Xml.Linq</AssemblyReference>

       <AssemblyReference>mscorlib</AssemblyReference>

       <AssemblyReference>DataExchangeWorkflows</AssemblyReference>

     </sco:Collection>

   </TextExpression.ReferencesForImplementation>

   <Sequence sap2010:WorkflowViewState.IdRef="Sequence_1">

     <Sequence.Variables>

       <Variable x:TypeArguments="p:CorrelationHandle" Name="_handler" />

       <Variable x:TypeArguments="x:Int32" Default="-1" Name="TicketId" />

     </Sequence.Variables>

     <Pick sap2010:WorkflowViewState.IdRef="Pick_1">

       <PickBranch DisplayName="Branch1" sap2010:WorkflowViewState.IdRef="PickBranch_1">

         <PickBranch.Trigger>

           <p:Receive CanCreateInstance="True" sap2010:WorkflowViewState.IdRef="Receive_2" OperationName="ReceiveOrder" />

         </PickBranch.Trigger>

         <Sequence sap2010:WorkflowViewState.IdRef="Sequence_2">

           <Assign sap2010:WorkflowViewState.IdRef="Assign_1">

             <Assign.To>

               <OutArgument x:TypeArguments="x:Int32">

                 <mca:CSharpReference x:TypeArguments="x:Int32">TicketId</mca:CSharpReference>

               </OutArgument>

             </Assign.To>

             <Assign.Value>

               <InArgument x:TypeArguments="x:Int32">

                 <mca:CSharpValue x:TypeArguments="x:Int32">new Random().Next()</mca:CSharpValue>

               </InArgument>

             </Assign.Value>

           </Assign>

           <p:InitializeCorrelation sap2010:WorkflowViewState.IdRef="InitializeCorrelation_1">

             <p:InitializeCorrelation.Correlation>

               <InArgument x:TypeArguments="p:CorrelationHandle">

                 <mca:CSharpValue x:TypeArguments="p:CorrelationHandle">_handler</mca:CSharpValue>

               </InArgument>

             </p:InitializeCorrelation.Correlation>

             <InArgument x:TypeArguments="x:String" x:Key="Id">

               <mca:CSharpValue x:TypeArguments="x:String">TicketId.ToString()</mca:CSharpValue>

             </InArgument>

           </p:InitializeCorrelation>

           <WriteLine sap2010:WorkflowViewState.IdRef="WriteLine_1">

             <InArgument x:TypeArguments="x:String">

               <mca:CSharpValue x:TypeArguments="x:String">"流程被创建,编号为:" + TicketId.ToString()</mca:CSharpValue>

             </InArgument>

           </WriteLine>

         </Sequence>

       </PickBranch>

     </Pick>

     <Pick sap2010:WorkflowViewState.IdRef="Pick_2">

       <PickBranch DisplayName="Branch1" sap2010:WorkflowViewState.IdRef="PickBranch_2">

         <PickBranch.Trigger>

           <p:Receive sap2010:WorkflowViewState.IdRef="Receive_3" OperationName="CheckCredit" ServiceContractName="ICheckCredit">

             <p:Receive.CorrelatesOn>

               <p:XPathMessageQuery x:Key="Id">

                 <p:XPathMessageQuery.Namespaces>

                   <ssx:XPathMessageContextMarkup>

                     <x:String x:Key="xgSc">http://tempuri.org/</x:String>

                   </ssx:XPathMessageContextMarkup>

                 </p:XPathMessageQuery.Namespaces>sm:body()/xgSc:CheckCredit/xgSc:id</p:XPathMessageQuery>

             </p:Receive.CorrelatesOn>

             <p:Receive.CorrelatesWith>

               <InArgument x:TypeArguments="p:CorrelationHandle">

                 <mca:CSharpValue x:TypeArguments="p:CorrelationHandle">_handler</mca:CSharpValue>

               </InArgument>

             </p:Receive.CorrelatesWith>

             <p:ReceiveParametersContent>

               <OutArgument x:TypeArguments="x:String" x:Key="action">

                 <mca:CSharpReference x:TypeArguments="x:String">action</mca:CSharpReference>

               </OutArgument>

               <OutArgument x:TypeArguments="x:String" x:Key="comment">

                 <mca:CSharpReference x:TypeArguments="x:String">comment</mca:CSharpReference>

               </OutArgument>

               <OutArgument x:TypeArguments="x:Int32" x:Key="id">

                 <mca:CSharpReference x:TypeArguments="x:Int32">reviewId</mca:CSharpReference>

               </OutArgument>

             </p:ReceiveParametersContent>

           </p:Receive>

         </PickBranch.Trigger>

         <If sap2010:WorkflowViewState.IdRef="If_1">

           <If.Condition>

             <InArgument x:TypeArguments="x:Boolean">

               <mca:CSharpValue x:TypeArguments="x:Boolean">action.ToUpper() == "APPROVAL"</mca:CSharpValue>

             </InArgument>

           </If.Condition>

           <If.Then>

             <WriteLine sap2010:WorkflowViewState.IdRef="WriteLine_2">

               <InArgument x:TypeArguments="x:String">

                 <mca:CSharpValue x:TypeArguments="x:String">"流程" + TicketId.ToString() + "通过审核"</mca:CSharpValue>

               </InArgument>

             </WriteLine>

           </If.Then>

           <If.Else>

             <WriteLine sap2010:WorkflowViewState.IdRef="WriteLine_3">

               <InArgument x:TypeArguments="x:String">

                 <mca:CSharpValue x:TypeArguments="x:String">"流程" + TicketId.ToString() + "被驳回"</mca:CSharpValue>

               </InArgument>

             </WriteLine>

           </If.Else>

         </If>

       </PickBranch>

     </Pick>

     <sads:DebugSymbol.Symbol>d2BFOlxLZXZpbl9Eb2N1bWVudFx3b3Jrc3BhY2VcRGF0YUV4Y2hhbmdlU29sdXRpb25cRGF0YUV4Y2hhbmdlV29ya2Zsb3dzXERhdGFFeGNoYW5nZUFjdGl2aXR5LnhhbWwbLwOOAQ4CAQEyMzI3AgECNAVXDAIBM1gFjAEMAgEDNQdWFAIBNFkHiwEUAgEENws3egIBVzkJVRQCATVbC3QXAgEadgmKAQ4CAQU6C0UUAgFKRgtPJQIBPVALVBcCATZmEWZiAgEtaxFrXQIBJ3ERcV4CASFuEW5eAgEbeQ95bAIBBn0NgQEZAgEThAENiAEZAgEMQhFCYQIBUT0RPV4CAUtND01gAgFESRFJYgIBPlIPUm8CATd/EX9yAgEUhgERhgFxAgEN</sads:DebugSymbol.Symbol>

   </Sequence>

   <sap2010:WorkflowViewState.ViewStateManager>

     <sap2010:ViewStateManager>

       <sap2010:ViewStateData Id="Receive_2" sap:VirtualizedContainerService.HintSize="255,90" />

       <sap2010:ViewStateData Id="Assign_1" sap:VirtualizedContainerService.HintSize="242,62" />

       <sap2010:ViewStateData Id="InitializeCorrelation_1" sap:VirtualizedContainerService.HintSize="242,97" />

       <sap2010:ViewStateData Id="WriteLine_1" sap:VirtualizedContainerService.HintSize="242,62" />

       <sap2010:ViewStateData Id="Sequence_2" sap:VirtualizedContainerService.HintSize="264,425">

         <sap:WorkflowViewStateService.ViewState>

           <scg:Dictionary x:TypeArguments="x:String, x:Object">

             <x:Boolean x:Key="IsExpanded">True</x:Boolean>

           </scg:Dictionary>

         </sap:WorkflowViewStateService.ViewState>

       </sap2010:ViewStateData>

       <sap2010:ViewStateData Id="PickBranch_1" sap:VirtualizedContainerService.HintSize="294,713" />

       <sap2010:ViewStateData Id="Pick_1" sap:VirtualizedContainerService.HintSize="608,759" />

       <sap2010:ViewStateData Id="Receive_3" sap:VirtualizedContainerService.HintSize="255,90" />

       <sap2010:ViewStateData Id="WriteLine_2" sap:VirtualizedContainerService.HintSize="211,62" />

       <sap2010:ViewStateData Id="WriteLine_3" sap:VirtualizedContainerService.HintSize="211,62" />

       <sap2010:ViewStateData Id="If_1" sap:VirtualizedContainerService.HintSize="464,212" />

       <sap2010:ViewStateData Id="PickBranch_2" sap:VirtualizedContainerService.HintSize="494,500" />

       <sap2010:ViewStateData Id="Pick_2" sap:VirtualizedContainerService.HintSize="608,546" />

       <sap2010:ViewStateData Id="Sequence_1" sap:VirtualizedContainerService.HintSize="630,1469">

         <sap:WorkflowViewStateService.ViewState>

           <scg:Dictionary x:TypeArguments="x:String, x:Object">

             <x:Boolean x:Key="IsExpanded">True</x:Boolean>

           </scg:Dictionary>

         </sap:WorkflowViewStateService.ViewState>

       </sap2010:ViewStateData>

       <sap2010:ViewStateData Id="DataExchangeWorkflows.DataExchangeActivity_1" sap:VirtualizedContainerService.HintSize="670,1549" />

     </sap2010:ViewStateManager>

   </sap2010:WorkflowViewState.ViewStateManager>

 </Activity>

3. Host项目引入System.Activities, System.ServiceModel.Activities和System.ServiceModel。如下图所示:

4. 修改Host项目的program.cs如下:

         static void Main(string[] args)

         {

             var host = new WorkflowServiceHost(

                 new DataExchangeActivity(),

                 new Uri("http://localhost:8080/WS"));

             host.AddDefaultEndpoints();

             host.Description.Behaviors.Add(

                 new ServiceMetadataBehavior() { HttpGetEnabled = true });

             host.AddServiceEndpoint(

                 "IMetadataExchange",

                 MetadataExchangeBindings.CreateMexHttpBinding(),

                 "mex");

             host.Open();

             Console.WriteLine("Server is ready.");

             Console.Read();

         }

5. 编译Host,然后以Administrator身份运行host.exe,这时会启动WCF,终端窗口显示如下:

6. 这时打开浏览器,浏览http://localhost:8080/ws,会显示如下页面:

7. 打开VS Command Prompt(VS命令行终端),运行svcutil.exe http://localhost:8080/ws?wsdl。结果如下图。这时会生成两个文件,DataExchangeActivity.cs和output.config。将这两个文件copy到client项目中,output.config改名为app.config。

8. 修改Client的Form1,界面如下:

9. 代码如下(很简单就不解释了):

         private void button1_Click(object sender, EventArgs e)

         {

             var proxy = new DataExchangeActivityClient();

             proxy.ReceiveOrder();

         }

         private void button2_Click(object sender, EventArgs e)

         {

             var proxy = new CheckCreditClient();

             proxy.CheckCredit(textAction.Text.Trim(), "", int.Parse(textId.Text));

         }

10. 运行Client后,启动流程并且输入对应工作流的审批意见后,结果如下:

源代码下载

Workflow:实现一个简单的审批流程的更多相关文章

  1. Springboot 整合Activiti流程设计器 完成一个简单的请假流程

    目录 1.前言 2.准备 3.下载解压 4.开始整合 mysql + activiti + thymeleaf 2.配置文件 3.复制文件 4.加入控制器 5.修改配置文件 6.剔除启动类里面的安全校 ...

  2. 【Star CCM+实例】开发一个简单的计算流程.md

    流程开发在CAE过程中处于非常重要的地位. 主要的作用可能包括: 将一些经过验证的模型隐藏在流程中,提高仿真的可靠性 将流程封装成更友好的界面,降低软件的学习周期 流程开发实际上需要做非常多的工作,尤 ...

  3. 一个简单CI/CD流程的思考

    因为公司有两地研发团队,在统一CI/CD上难度不亚于两家公司合并后的新流程建立,并非不可攻克,简单描述下心得. 首先,代码管理使用gerrit -> 因其强大的 codereview 功能被选中 ...

  4. 一个基于activiti审批流程示例,如何与系统整合

    前言 目前市场上有很多开源平台没有整合工作流,即使有,也是价格不菲的商业版,来看这篇文章的估计也了解了行情,肯定不便宜.我这个快速开发平台在系统基础功能(用户管理,部门管理-)上整合了工作流,你可以直 ...

  5. 基于SpringCloud的微服务架构实战案例项目,以一个简单的购物流程为示例

    QuickStart 基于SpringCloud体系实现,简单购物流程实现,满足基本功能:注册.登录.商品列表展示.商品详情展示.订单创建.详情查看.订单支付.库存更新等等. 每个业务服务采用独立的M ...

  6. uiautomator 一个简单脚本创建流程

    http://www.codeceo.com/article/android-ui-auto-test.html

  7. 我的第一个activiti实例 (代码方式) ctiviti入门列子一个简单的activiti请假流程

    转: (activiti入门列子一个简单的activiti请假流程) 我的第一个activiti实例 2017年05月31日 14:29:45 chf_mixueer 阅读数:1223   整个项目的 ...

  8. Python的网络编程[5] -> BOOTP + TFTP + FTP -> 实现一个简单的文件传输流程

    BOOTP-TFTP-FTP 目录 文件传输流程 服务器建立过程 客户端建立过程 1 文件传输流程 / File Transfer Flow 利用BOOTP,TFTP,FTP三种传输协议,建立起客户端 ...

  9. 一个简单的Eclipse调试Debug流程(四)

    本文链接:https://blog.csdn.net/u011781521/article/details/55000066    http://blog.csdn.net/u010075335/ar ...

随机推荐

  1. ZOJ3714JavaBeans

    #!/usr/bin/env python # encoding: utf-8 t = int(raw_input()) for i in range(t): n,k = [int(x) for x ...

  2. CTSC+APIO+THUACM游记

    退役之前,写点破事乐呵乐呵.. (同DaD3zZ) CTSC Day0 来到丽都 哈哈哈这可是四星级豪华酒店啊   想想要在这住7天  美滋滋 换了半天的房间 也没有换到一起   最后yzy& ...

  3. form表单中图片也可以当作提交按钮

    点击图片按钮时,不光提交其他输入框信息,还把鼠标点击图片上的x,y坐标也传输过去了

  4. Zookeeper概念学习系列之zookeeper的数据模型

    1.层次化的目录结构,命名符合常规文件系统规范. 2.每个节点在zookeeper中叫做znode,并且有其有一个唯一的路径标识. 3.znode中的数据可以有多个版本,比如某一路径下存有多个数据版本 ...

  5. [ SDOI 2011 ] 打地鼠

    \(\\\) \(Description\) 给出一个\(N\times M\)的矩阵,你可以自由确定一个\(R\times C(R,C>0)\)的矩形,使得可以多个用矩形覆盖整个矩阵,覆盖的定 ...

  6. python基础篇(一)-------- 字符串的操作

    1.字符串的常用操作: 已知字符串:str = "hello world zhangsan and zhangsan" 1.字符串的长度:len(str) 2.查看字符串的索引值: ...

  7. canvas烟花锦集

    canvas可以实现不同动画效果,本文主要记录几种不同节日烟花效果实现. 实现一 效果地址 html <canvas id="canvas"></canvas&g ...

  8. C#入门经典 Chapter4 流程控制

    4.1布尔逻辑 布尔比较运算符 ==  !=   <   >    <=    >= 处理布尔值的布尔值运算符 ! & | ^(异或) 条件布尔运算符 &&am ...

  9. [Windows Server 2012] Tomcat安全加固方法

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com ★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频. ★ 本节我们将带领大家:Tomca ...

  10. Random同时生成多个随机数

    贴一个简单示例 public DataTable selectStuInfo() { DataTable dt = new DataTable(); dt.Columns.Add("姓名&q ...