WF4.0 基础篇 (二十六) Interop调用WF3.X的Activity
2010-04-01 14:49
477 查看
本节主要介绍Interop调用WF3.X的Activity
本文例子下载:
http://files.cnblogs.com/foundation/InteropSample.rar
本文例子说明
![](http://images.cnblogs.com/cnblogs_com/foundation/040110_0648_WF401.png)
Interop调用WF3.X的Activity
![](http://images.cnblogs.com/cnblogs_com/foundation/040110_0648_WF402.png)
使用说明
默认有WF4.0项目为[.NET Framework 4 Client Profile],要使用Interop,应将项目改为[.NET Framework 4 ]
![](http://images.cnblogs.com/cnblogs_com/foundation/040110_0648_WF403.png)
Interop默认没出现在工具栏中,需要添加
![](http://images.cnblogs.com/cnblogs_com/foundation/040110_0648_WF404.png)
[ActivityType属性]用于指定要调用的WF3.5的Activity的类型
![](http://images.cnblogs.com/cnblogs_com/foundation/040110_0648_WF405.png)
![](http://images.cnblogs.com/cnblogs_com/foundation/040110_0648_WF406.png)
当指定WF3.5的Activity的类型后,在设计器中会自动为WF3.5的Activity的绑定生成两个参数一个为[属性名],另一个为[属性名Out]
![](http://images.cnblogs.com/cnblogs_com/foundation/040110_0648_WF407.png)
例子1:调用WF3.X的Activity
说明:
1.创建一WF3.X的Activity,有一绑定属性[printText]
Activity在[ Execute]方法中打印[printText]的值,并为[printText]赋予一新值
2.创建一WF4的工作流,用[Interop]调用WF3.X的Activity,为[printText]传入值,并打印通过[printText]的返回值
例2:代码操作
本文例子下载:
http://files.cnblogs.com/foundation/InteropSample.rar
本文例子说明
![](http://images.cnblogs.com/cnblogs_com/foundation/040110_0648_WF401.png)
Interop调用WF3.X的Activity
类名 | System.Activities.Statements.Interop |
文件 | System.Workflow.Runtime.dll |
结构说明 | 继承 NativeActivity, ICustomTypeDescriptor 是一个 sealed类 override 了 [CacheMetadata方法] 与 [Cancel方法] 与[Execute方法] override 了 [CanInduceIdle属性] [ActivityMetaProperties]属性的类型为[IDictionary<string, object>] [ActivityProperties]属性的类型为[IDictionary<string, object>] [ActivityType]属性的类型为[Type] |
功能说明 | [ActivityType属性]用于指定要调用的WF3.5的Activity的类型 当指定WF3.5的Activity的类型后,在设计器中会自动为WF3.5的Activity的绑定生成两个参数一个为[属性名],另一个为[属性名Out] |
![](http://images.cnblogs.com/cnblogs_com/foundation/040110_0648_WF402.png)
使用说明
默认有WF4.0项目为[.NET Framework 4 Client Profile],要使用Interop,应将项目改为[.NET Framework 4 ]![](http://images.cnblogs.com/cnblogs_com/foundation/040110_0648_WF403.png)
Interop默认没出现在工具栏中,需要添加
![](http://images.cnblogs.com/cnblogs_com/foundation/040110_0648_WF404.png)
[ActivityType属性]用于指定要调用的WF3.5的Activity的类型
![](http://images.cnblogs.com/cnblogs_com/foundation/040110_0648_WF405.png)
![](http://images.cnblogs.com/cnblogs_com/foundation/040110_0648_WF406.png)
当指定WF3.5的Activity的类型后,在设计器中会自动为WF3.5的Activity的绑定生成两个参数一个为[属性名],另一个为[属性名Out]
![](http://images.cnblogs.com/cnblogs_com/foundation/040110_0648_WF407.png)
例子1:调用WF3.X的Activity
说明:1.创建一WF3.X的Activity,有一绑定属性[printText]
Activity在[ Execute]方法中打印[printText]的值,并为[printText]赋予一新值
2.创建一WF4的工作流,用[Interop]调用WF3.X的Activity,为[printText]传入值,并打印通过[printText]的返回值
WF3.X的Activity | public partial class myActivity : Activity { public myActivity() { InitializeComponent(); } [System.Diagnostics.DebuggerNonUserCode] [System.CodeDom.Compiler.GeneratedCode("", "")] private void InitializeComponent() { this.Name = "myActivity"; } public static readonly DependencyProperty printTextProperty = DependencyProperty.Register("printText", typeof(string), typeof(myActivity)); public string printText { get { return (string)base.GetValue(printTextProperty); } set { base.SetValue(printTextProperty, value); } } protected override ActivityExecutionStatus Execute(ActivityExecutionContext context) { Console.WriteLine(this.printText); this.printText = printText + ":wxd"; return ActivityExecutionStatus.Closed; } } |
WF4的工作流 | ![]() |
宿主 | static void test1() { WorkflowInvoker.Invoke(new testWorkflow()); } |
结果 | ![]() |
例2:代码操作
static void test2() { Variable<string> myVariable = new Variable<string>() { Default = "wxwinter" }; Sequence root = new Sequence() { Variables = { myVariable }, Activities = { new Interop() { ActivityType = typeof(myActivity), ActivityProperties = { { "printText", new InArgument<string>(myVariable) } , { "printTextOut", new OutArgument<string>(myVariable) } }, ActivityMetaProperties = { // Provide a value for the Name meta-property of the WriteLine { "Name", "myActivity" } } } , new WriteLine{ Text=myVariable} } }; WorkflowInvoker.Invoke(root); } |
![]() |
相关文章推荐
- WF4.0 基础篇 (二十六) Interop调用WF3.X的Activity
- WF4.0 基础篇 (二十八) WF调用PowerShell
- WF4.0 基础篇 (二十八) WF调用PowerShell
- WF4.0 基础篇 (一)开始使用WF
- WF4.0 基础篇 (九) 控制流Activity
- [WF4.0 实战] WPF + WCF + WF 打造Hello World(基础篇)
- WF4.0 基础篇 (二) Activity介绍及WriteLine Activity的使用
- WF4.0 基础篇 (三) 流程实例WorkflowApplication与设计WF程序的基本原则
- WF4.0 Beta1之旅(7):WF调用PowerShell
- WF工作流技术内幕 —— 以InvokeWebServiceActivity在Workflow工作流调用Web服务
- WF4.0 基础篇 (二十七) WCF Workflow Service 在WCF中使用WF
- WF4.0 基础篇 (八) 控制流Activity
- WF4.0 基础篇 (二十三) 范型Activity
- WF4.0 基础篇 (三十 完) 对学习WF的一点建议
- WF4.0 基础篇 (一)开始使用WF
- WF4.0 基础篇 (二十四) Async Activity
- WF4.0 基础篇 (三十 完) 对学习WF的一点建议
- WF4.0 基础篇 (一)开始使用WF
- WF4.0 基础篇 (九) 控制流Activity
- WF4.0 基础篇 (十三) InvokeMethod 调用方法