2010-11-03 69 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>