开发者

Workflow 4.0 and Collections

I want to write a simple application to help me understand workflow 4.0 a bit. I have a sequence activity with a ReceiveAndSendRepply activity to communicate with my silverlight application.

I want to create a List of Type Students and in my silverlight application, display in the datagrid.

At the moment, I have a simple class Student

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

I am exposing my WF as a service and calling it from my silverlight app:

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();       
        }

I am able to use the assign A-B and assign a variable and give it ONE value but I want to send multiple values and ierate through them.

How do I go about having a List of students and iterate and display in grid.

How do I creat开发者_如何转开发e a list in workflow and send it back to the Silverlight grid?


Just return a List from your workflow service and the Silverlight client will receive that.

The workflow

Workflow 4.0 and Collections

The Silverlight client

Workflow 4.0 and Collections

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;   
}

The complete workflow service XAMLX source looks like this:

<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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜