本文主要介绍如何使用SendParameters和ReceiveParameters的使用,这两个活动允许你在调用服务的时候携带多个参数。 在Workflow Service上主要体现在Send,Receive,SendReply,ReceiveReply活动的Content属性的设置上。
下面的例子将通过使用SendParameters和ReceiveParameters将参数从客户端传到服务端,确认后给客户端发送回复。
1.服务端工作流ServiceWF流程设置如下图:
工作流变量如下:
Name |
Type |
Scope |
Default |
servicemsg |
String |
Sequence |
|
para |
String |
Sequence |
|
流程设计如下:
使用WorkflowServiceHost宿主工作流如下:
class Program
{
static void
{
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 Message
|
Result |
String |
Sequence |
|
流程设计如下:
客户端调用程序如下:
class Program
{
static void
{
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.结果如下:
本文转自生鱼片博客园博客,原文链接:http://www.cnblogs.com/carysun/archive/2009/12/11/WF4-SendPara.html,如需转载请自行联系原作者