WF3.0 CallExternalMethod使用技巧
CallExternalMethod用于工作流向宿主进程中通信 简单的介绍一下它的使用技巧,参照网上的一个questioner源码进行了改进,因为我感觉这个源码提供的通信demo过于繁琐。
看看service代码
namespace QuestionService { [ExternalDataExchange] public interface ITestService { void SendResponseDataToHost(TestPara responses); } }
TestPara对象是对参数的一个封装,因为按照我的测试,在调用接口方法中,方法的参数如果不是对象类型,就会无法解决工作流传参的问题。
namespace QuestionService { [Serializable] public class TestArgs : ExternalDataEventArgs { protected TestPara _dataValue = null; public TestPara Responses { get { return _dataValue; } } public TestArgs(Guid instanceId, TestPara responses) : base(instanceId) { _dataValue = responses; } } [Serializable] public class TestPara { protected bool[] _dataValue = null; public bool[] Responses { get { return _dataValue; } set { _dataValue = value; } } } }
这是实现的关键地方,DataAvailable事件用于向宿主进程暴露
namespace QuestionService { [Serializable] public class TestService : ITestService { #region ITestService 成员 public event EventHandler<TestArgs> DataAvailable; public void SendResponseDataToHost(TestPara responses) { if (DataAvailable != null) { try { DataAvailable(this, new TestArgs(WorkflowEnvironment.WorkflowInstanceId, responses)); } catch (Exception ex) { } } // if } #endregion } }
在工作流中 要设置相关的接口协议,选择调用的方法
需要注意的是 参数要在工作流中设置参数的属性 以供其选择,其中_response是工作流活动返回的数据,这里通过TestPara属性进行封装获取
private bool[] _response = null; private TestPara _TestPara = new TestPara(); public TestPara TestPara { get { _TestPara.Responses = _response; return _TestPara; } }
最后是宿主调用的过程 对调用进行了改动 DataAvailable事件暴露给宿主进程。以供工作流进程调用。
private void cmdExecute_Click(object sender, EventArgs e) { // Disable the execute button cmdExecute.Enabled = false; // Clear the indicators ClearIndicators(); // Set the cursor to "app starting" Cursor = Cursors.AppStarting; // Process the request, starting by creating the parameters Dictionary<string, object> parms = new Dictionary<string, object>(); parms.Add(); ]; questions[] = tbQuestion1.Text; questions[] = tbQuestion2.Text; questions[] = tbQuestion3.Text; parms.Add("Questions", questions); // Create instance. _workflowInstance = _workflowRuntime.CreateWorkflow(typeof(QuestionFlow.Workflow1), parms); if (_dataExchangeService==null) { _dataExchangeService = new ExternalDataExchangeService(); _workflowRuntime.AddService(_dataExchangeService); TestService _testService = new TestService(); _testService.DataAvailable += new EventHandler<QuestionService.TestArgs>(dataService_DataAvailable); _dataExchangeService.AddService(_testService); } // Hook returned data event //QuestionService.WorkflowResponseDataService dataService = QuestionService.WorkflowResponseDataService.CreateDataService(_workflowInstance.InstanceId, _workflowRuntime); // Start instance. _workflowInstance.Start(); } public void dataService_DataAvailable(object sender, QuestionService.TestArgs e) { IAsyncResult result = this.BeginInvoke( new EventHandler( delegate { // Retrieve connection. //QuestionService.WorkflowResponseDataService dataService = QuestionService.WorkflowResponseDataService.GetRegisteredWorkflowDataService(e.InstanceId); // Read the response data bool[] responses = e.Responses.Responses; // Bind the vehicles list to the vehicles table SetIndicators(responses); } // delegate ), null, null ); // BeginInvoke this.EndInvoke(result); // Reset for next request WorkflowCompleted(); } private delegate void WorkflowCompletedDelegate(); private void WorkflowCompleted() { IAsyncResult result = this.BeginInvoke( new EventHandler( delegate { // Reset the cursor Cursor = Cursors.Arrow; // Enable the execute button cmdExecute.Enabled = true; } // delegate ), null, null ); // BeginInvoke this.EndInvoke(result); }
WF3.0 CallExternalMethod使用技巧的更多相关文章
- VC6.0实用小技巧
VC6.0的若干实用小技巧 .检测程序中的括号是否匹配 把光标移动到需要检测的括号(如大括号{}.方括号[].圆括号()和尖括号<>)前面,键入快捷键 “Ctrl+]”.如果括号匹配正确, ...
- nyoj--84--阶乘的0(数学技巧)
阶乘的0 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 计算n!的十进制表示最后有多少个0 输入 第一行输入一个整数N表示测试数据的组数(1<=N<=100 ...
- 0.0.Pycharm使用技巧
调整自动字体大小 Increase(字体变大) Decrease(字体变小) 背景颜色设置 pycharm 左侧菜单问题 解决 pycharm中配置启动Django项目 1.先打开mange.py,然 ...
- arcgis中nodata设为0及其小技巧
一.arcgis中nodata设为0 两个栅格进行叠加,有时会有一部分没有数据,即用identify点击该区域,Value为NoDat a,而不是像其他非空区域一样有值. 此时注意nodata区域要赋 ...
- Android 4.0的图形硬件加速及绘制技巧
转:http://zuiniuwang.blog.51cto.com/3709988/721798 从Android 3.0开始,Android 2D的绘制流程就设计为能够更好地支持硬件加速.使用GP ...
- 前端读者 | 关于存储及CSS的一些技巧
@羯瑞 HTML5存储 cookies 大小限制4K 发送在http请求头中 子域名能读取主域名的cookies 本地存储 localStorage sessionStorage 大小限制5M(注意超 ...
- cssfloat布局以及其他小技巧
css float 布局以及其他小技巧总结 这篇博文 前面四个部分是关于css 经典布局 如果你已经知道了 可以直接跳过看第六部分 css 的其他小技巧 1.0 左右居中布局 <!DOCTYPE ...
- TensorFlow2.0使用方法
TensorFlow2.0 1 使用技巧 更新到最新版本: pip install --upgrade tensorflow pip install --upgrade tensorflow-gpu ...
- 利用Shell脚本将MySQL表中的数据转化为json格式
脚本如下: #!/bin/bash mysql -s -phello test >.log <<EOF desc t1; EOF lines="concat_ws(',', ...
随机推荐
- manacher 最长回文子串
确定当前已知能匹配到的最长处,看是否要更新最长 #include <bits/stdc++.h> using namespace std; const int N = 210005; in ...
- poj: 1003
简单题 #include <iostream> #include <stdio.h> #include <string.h> #include <stack& ...
- android ANR问题
一.什么是ANR ANR:Application Not Responding: 具体请参考:http://blog.csdn.net/dadoneo/article/details/8270107
- eclipse批量删除断点(转)
1.首先调出BreakPoints选项卡(Window--show View--Other--BreakPoints). 2.选择BreakPoints选项卡,选择所有断点,点击删除即可.
- web server与app server有什么不同
简单来说,web服务器提供页面给浏览器,而app服务器提供客户端可以调用的接口.具体而言,我们可以说: Web服务器处理HTTP请求,而app服务器基于多种不同的协议,处理应用程序的逻辑问题. 以下将 ...
- Android使用ZXing生成带图片的二维码
效果图如下: 制作过程很简单的就是在原始的二维码图片上添加一个logn图标,代码的注释写得很详细,也就不给大家啰嗦了 package com.example.day44_02_qrcodewithlo ...
- [转]IP动态切换脚本
因为公司办公室要设置固定IP才行,而家里的IP段和公司是不一样的,家里采用了DHCP机制,这样每次就得改IP设置,很是不方便,就写了这个脚本来动态切换,很流畅的说!WINXP,WIN7测试通过~嘿嘿~ ...
- 怎么查看windows2003中隐藏用户
在命令模式下删除1.你在MS-dos下先输入net user 看有那些用户, 注意第一步看不出隐藏的用户 2.然后在输入net localgroup administrators 或者 net loc ...
- app_field.clear_dependent_fields
可以调用APP_FIELD.clear_dependent_fields和APP_FIELD.set_dependent_field来将两个(或多个)Item建立关联,当一个为空时,另一个不可录入,反 ...
- 夺命雷公狗---DEDECMS----5快速入门之商城快速搭建实现快递方式和支付方式的显示
我们现在用dedecms快速搭建一个商场,方法如下所示: 如此类推.写多几个栏目,效果 如下所示: 然后我们添加几个商品,记得要刷新下页面噢,不见见不到商品 添加成功后去看看效果如何: 出来了,但是如 ...