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(',', ...
随机推荐
- PostgreSQL Replication之第十一章 使用Skytools(5)
11.5 关于walmgr 的介绍 walmgr 是一个简化基于文件事务日志传输的工具.早在过去的一些日子里(在9.0版本之前),使用walmgr来简化基本备份是很常见的.随着流复制的引入,情况有了一 ...
- G面经prepare: Sort String Based On Another
Given a sorting order string, sort the input string based on the given sorting order string. Ex sort ...
- SQL 自动增长 identity
create table Users( id ,),--id 从10000开始,增加长度为1 name ), ); --执行三次这个语句 insert into Users values('小昆虫') ...
- 转:python webdriver API 之下拉框处理
下拉框也是 web 页面上非常常见的功能,webdriver 对于一般的下拉框处理起来也相当简单,要想定位下拉框中的内容,首先需要定位到下拉框:这样的二次定位,我们在前面的例子中已经有过使用,下面通过 ...
- introcuding less css with less.js, using webcompiler ext
1.html [watch out for the !js load sequence and the attribute of !rel stylesheet/less!] <!DOCTYPE ...
- python在window下的Nginx部署
Python版本3.21 安装nginx下载windows上的nginx最新版本,http://www.nginx.org/en/download.html.解压后即可.运行nginx.exe后本地打 ...
- PHP中的赋值运算符
PHP的赋值运算符有两种,分别是: (1)“=”:把右边表达式的值赋给左边的运算数.它将右边表达式值复制一份,交给左边的运算数.换而言之,首先给左边的运算数申请了一块内存,然后把复制的值放到这个内存中 ...
- monkey测试(转)
一.Monkey测试简介Monkey测试是Android平台自动化测试的一种手段,通过Monkey程序模拟用户触摸屏幕.滑动Trackball.按键等操作来对设备上的程序进行压力测试,检测程序多久的时 ...
- linux第1天 fork exec 守护进程
概念方面 文件是对I/O设备的抽象表示.虚拟存储器是对主存和磁盘I/O设备的抽象表示.进程则是对处理器.主存和I/O设备的抽象表示 中断 早期是没有进程这个概念,当出现中断技术以后才出现进程这个概念 ...
- ligerui+json_002_Grid用法、属性总结
原文更全面,地址: http://blog.csdn.net/dxnn520/article/details/8216560 // ================================== ...