WF3.5 的SendActivity、ReceiveActivity与WorkflowServiceHost (4)

ReceiveActivity 对话模式

 

CanCreateInstance设置为 false,客户端无法使用服务操作调用来创建工作流的新实例,只能使用关联的 WorkflowRuntime 对象的 CreateWorkflow 方法可以创建这样的工作流,并作为对话的一部分由服务客户端调用

流程说明

 

系统结构说明

 

调用说明

 

服务接口

namespace 基础类

{

[System.Runtime.Serialization.DataContract]

public class 物料单

{

[System.Runtime.Serialization.DataMember]

public string 要申请的物料

{ set; get; }

 

 

[System.Runtime.Serialization.DataMember]

public string 协调计划

{ set; get; }

}

 

[ServiceContract]

public interface 物料申请

{

[OperationContract(IsInitiating = true)]

void 提交申请单(物料单 物料申请单 ,IDictionary<string,string> myContext);

}

[ServiceContract]

public interface 回复物料申请

{

[OperationContract(IsInitiating = true)]

void 回复请单(物料单 物料申请单);

}

}

 

生产部服器_申请物料流程

<system.serviceModel>

<services>

<service name="生产部服器.申请物料流程" >

<host>

<baseAddresses>

<add baseAddress="http://localhost:5001/wxwinter/" />

</baseAddresses>

</host>

<endpoint address=""

binding="wsHttpContextBinding"

contract="基础类.回复物料申请" />

</service>

</services>

<client>

<endpoint name="lzmEndPoint"

address="http://localhost:5000/wxwinter/"

binding="wsHttpContextBinding"

contract="基础类.物料申请">

</endpoint>

</client>

</system.serviceModel>

public sealed partial class 申请物料流程: SequentialWorkflowActivity

    {

        public 申请物料流程()

        {

            InitializeComponent();

        }

 

public 基础类.物料单 物料申请单 = new 基础类.物料单();

 

private void codeActivity1_ExecuteCode(object sender, EventArgs e)

{

物料申请单.要申请的物料 = "电脑";

System.Console.WriteLine(this.WorkflowInstanceId.ToString());

 

 

}

private void sendActivity1_BeforeSend(object sender, SendActivityEventArgs e)

{

e.SendActivity.ParameterBindings["myContext"].Value = this.receiveActivity1.Context;

}

 

private void codeActivity2_ExecuteCode(object sender, EventArgs e)

{

System.Console.WriteLine(物料申请单.要申请的物料);

System.Console.WriteLine(物料申请单.协调计划);

System.Console.WriteLine("完成");

}

 

 

    }

namespace 生产部服器

{

class Program

{

static void Main(string[] args)

{

WorkflowServiceHost host = new WorkflowServiceHost(typeof(申请物料流程));

host.Open();

Console.WriteLine(host.BaseAddresses[0].ToString());

 

WorkflowInstance workflow = host.Description.Behaviors.Find<WorkflowRuntimeBehavior>().WorkflowRuntime.CreateWorkflow(typeof(申请物料流程));

workflow.Start();

Console.ReadLine();

host.Close();

}

}

}

 

 

协调部服器_协调流程

<system.serviceModel>

<services>

<service name="协调部服器.协调流程" >

<host>

<baseAddresses>

<add baseAddress="http://localhost:5000/wxwinter/" />

</baseAddresses>

</host>

<endpoint address=""

binding="wsHttpContextBinding"

contract="基础类.物料申请" />

</service>

</services>

<client>

<endpoint name="wxdEndPoint"

address="http://localhost:5001/wxwinter/"

binding="wsHttpContextBinding"

contract="基础类.回复物料申请">

 

</endpoint>

</client>

 

</system.serviceModel>

public sealed partial class 协调流程: SequentialWorkflowActivity

    {

        public 协调流程()

        {

            InitializeComponent();

        }

 

private void codeActivity1_ExecuteCode(object sender, EventArgs e)

{

this.sendActivity1.Context = this.receiveActivity1.ParameterBindings["myContext"].Value as IDictionary<string, string>;

}

 

public 基础类.物料单 物料申请单 = new 基础类.物料单();

 

private void codeActivity2_ExecuteCode(object sender, EventArgs e)

{

System.Console.WriteLine(this.WorkflowInstanceId.ToString());

Form1 f = new Form1();

f.textBox1.Text = 物料申请单.要申请的物料;

f.Text = this.WorkflowInstanceId.ToString();

f.ShowDialog();

物料申请单.协调计划 = f.textBox2.Text;

f.Close();

}

 

private void codeActivity3_ExecuteCode(object sender, EventArgs e)

{

System.Console.WriteLine("完成");

}

    }

namespace 协调部服器

{

class Program

{

 

static void Main(string[] args)

{

WorkflowServiceHost host = new WorkflowServiceHost(typeof(协调部服器.协调流程));

System.Workflow.Runtime.WorkflowRuntime runtime;

runtime = host.Description.Behaviors.Find<WorkflowRuntimeBehavior>().WorkflowRuntime;

host.Open();

Console.WriteLine(host.BaseAddresses[0].ToString());

Console.Read();

host.Close();

}

}

}

 

运行结果

 

 

 

例子:https://files.cnblogs.com/wxwinter/TestReceiveSendActivity.rar

 

posted @ 2008-05-23 09:15  WXWinter(冬)  阅读(1991)  评论(3编辑  收藏  举报