2010-11-03 67 views
0

我想编写一个简单的应用程序来帮助我理解工作流程4.0一点。我有一个使用ReceiveAndSendRepply活动的序列活动来与我的Silverlight应用程序进行通信。工作流程4.0和集合

我想创建一个类型的学生列表,并在我的silverlight应用程序中显示在数据网格中。

目前,我有一个简单的类学生

public class Student 
{ 
     public int ID { get; set; } 
     public string Name { get; set; } 
} 

我暴露我的WF作为一种服务,并从我的Silverlight应用程序调用它:

StudentService.ServiceClient client = new StudentService.ServiceClient(); 
     public MainPage() 
     { 

      InitializeComponent(); 
      client.GetStudentsCompleted += new EventHandler<StudentService.GetStudentsCompletedEventArgs>(client_GetStudentsCompleted); 
     } 

     private void Button_Click(object sender, RoutedEventArgs e) 
     { 

      client.GetStudentsAsync();  
     } 

我能够使用分配AB并分配一个变量并赋予它一个值,但我想发送多个值并通过它们进行调整。

我该如何去做一个学生列表并迭代并在网格中显示。

如何在工作流中创建列表并将其发送回Silverlight网格?

回答

2

只需从您的工作流服务中返回一个List,Silverlight客户端就会收到该列表。

工作流程 alt text

Silverlight客户端

alt text

private void button1_Click(object sender, RoutedEventArgs e) 
{ 
    var proxy = new ServiceClient(); 
    proxy.GetStudentsCompleted += new EventHandler<GetStudentsCompletedEventArgs>(proxy_GetStudentsCompleted); 
    proxy.GetStudentsAsync(); 
} 

void proxy_GetStudentsCompleted(object sender, GetStudentsCompletedEventArgs e) 
{ 
    dgStudents.ItemsSource = e.Result; 
} 

完整的工作流服务XAMLX来源是这样的:

<WorkflowService mc:Ignorable="sap" ConfigurationName="Service1" sap:VirtualizedContainerService.HintSize="339,620" Name="Service1" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/servicemodel" xmlns:d="clr-namespace:DeclarativeServiceLibrary1;assembly=DeclarativeServiceLibrary1" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="clr-namespace:Microsoft.VisualBasic;assembly=System" xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities" xmlns:p="http://tempuri.org/" xmlns:p1="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:s1="clr-namespace:System;assembly=System" xmlns:s2="clr-namespace:System;assembly=System.Xml" xmlns:s3="clr-namespace:System;assembly=System.Core" xmlns:s4="clr-namespace:System;assembly=System.ServiceModel" xmlns:sa="clr-namespace:System.Activities;assembly=System.Activities" xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities" xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation" xmlns:scg="clr-namespace:System.Collections.Generic;assembly=System" xmlns:scg1="clr-namespace:System.Collections.Generic;assembly=System.ServiceModel" xmlns:scg2="clr-namespace:System.Collections.Generic;assembly=System.Core" xmlns:scg3="clr-namespace:System.Collections.Generic;assembly=mscorlib" xmlns:sd="clr-namespace:System.Data;assembly=System.Data" xmlns:sl="clr-namespace:System.Linq;assembly=System.Core" xmlns:st="clr-namespace:System.Text;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <p1:Sequence DisplayName="Sequential Service" sad:XamlDebuggerXmlReader.FileName="c:\temp\DeclarativeServiceLibrary1\DeclarativeServiceLibrary1\Service1.xamlx" sap:VirtualizedContainerService.HintSize="309,590" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces"> 
    <p1:Sequence.Variables> 
     <p1:Variable x:TypeArguments="CorrelationHandle" Name="handle" /> 
     <p1:Variable x:TypeArguments="scg3:List(d:Student)" Default="[New List(Of DeclarativeServiceLibrary1.Student)]" Name="students" /> 
    </p1:Sequence.Variables> 
    <sap:WorkflowViewStateService.ViewState> 
     <scg3:Dictionary x:TypeArguments="x:String, x:Object"> 
     <x:Boolean x:Key="IsExpanded">True</x:Boolean> 
     </scg3:Dictionary> 
    </sap:WorkflowViewStateService.ViewState> 
    <Receive x:Name="__ReferenceID0" CanCreateInstance="True" DisplayName="ReceiveRequest" sap:VirtualizedContainerService.HintSize="287,90" OperationName="GetStudents" ServiceContractName="p:IService"> 
     <Receive.CorrelationInitializers> 
     <RequestReplyCorrelationInitializer CorrelationHandle="[handle]" /> 
     </Receive.CorrelationInitializers> 
    </Receive> 
    <p1:ForEach x:TypeArguments="x:Int32" sap:VirtualizedContainerService.HintSize="287,206" Values="[Enumerable.Range(0, 10)]"> 
     <p1:ActivityAction x:TypeArguments="x:Int32"> 
     <p1:ActivityAction.Argument> 
      <p1:DelegateInArgument x:TypeArguments="x:Int32" Name="item" /> 
     </p1:ActivityAction.Argument> 
     <p1:AddToCollection x:TypeArguments="d:Student" Collection="[students]" DisplayName="AddToCollection&lt;Student&gt;" sap:VirtualizedContainerService.HintSize="257,100" Item="[New Student() With {.ID = item, .Name = &quot;Student &quot; &amp; item}]" /> 
     </p1:ActivityAction> 
    </p1:ForEach> 
    <SendReply Request="{x:Reference __ReferenceID0}" DisplayName="SendResponse" sap:VirtualizedContainerService.HintSize="287,90"> 
     <SendParametersContent> 
     <p1:InArgument x:TypeArguments="scg3:List(d:Student)" x:Key="students">[students]</p1:InArgument> 
     </SendParametersContent> 
    </SendReply> 
    </p1:Sequence> 
</WorkflowService>