博客园  :: 首页  :: 联系 :: 订阅 订阅  :: 管理

WF4 Workflow Service:SendParameters和ReceiveParameters

Posted on 2009-12-11 21:29  生鱼片  阅读(2433)  评论(4编辑  收藏  举报

本文主要介绍如何使用SendParametersReceiveParameters的使用,这两个活动允许你在调用服务的时候携带多个参数。 在Workflow Service上主要体现在Send,Receive,SendReply,ReceiveReply活动的Content属性的设置上。

下面的例子将通过使用SendParametersReceiveParameters将参数从客户端传到服务端,确认后给客户端发送回复。
 

1.服务端工作流ServiceWF流程设置如下图: 

工作流变量如下:

Name

Type

Scope

Default

servicemsg

String

Sequence

 

para

String

Sequence

 

流程设计如下:

clip_image002

 

使用WorkflowServiceHost宿主工作流如下:

class Program

    {

       static void Main(string[] args)

        {               

            WorkflowService service = new WorkflowService

            {

                Name = "CaryService",

                Body = new cary.ServiceWF()

            };

            Uri address = new Uri("http://localhost:8080/CaryWFServices");

            WorkflowServiceHost host = new WorkflowServiceHost(service, address);

            try

            {

                Console.WriteLine("Opening service...");

                host.Open();

                Console.WriteLine("Service is listening on {0}...", address);

                Console.WriteLine("To terminate press ENTER");

                Console.ReadLine();

            }

            catch (Exception ex)

            {

                Console.WriteLine("Service terminated with exception {0}", ex.ToString());

            }

            finally

            {

                host.Close();

            }

        }

    }

2.客户端工作流ClientWF流程设置如下图:

工作流变量如下:

Name

Type

Scope

Default

Clientmsg

String

Sequence

“I am a client Message1”

Result

String

Sequence

 

 

流程设计如下:

clip_image004

客户端调用程序如下:

class Program

    {       

        static void Main(string[] args)

        {           

            try

            {

                WorkflowInvoker.Invoke(new cary.ClientWF());

                Console.WriteLine("Workflow completed successfully.");

            }

            catch (Exception e)

            {

            Console.WriteLine("Workflow completed with {0}: {1}.", e.GetType().FullName, e.Message);            }

            Console.WriteLine("To exit press ENTER.");

            Console.ReadLine();

        }       

    } 

3.结果如下: 

clip_image006