工作流程 4.0 和集合

发布于 2024-09-30 08:36:45 字数 937 浏览 8 评论 0原文

我想编写一个简单的应用程序来帮助我稍微了解一下工作流程 4.0。我有一个带有 ReceiveAndSendRepply 活动的序列活动来与我的 silverlight 应用程序进行通信。

我想创建一个学生类型列表,并在我的 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 网格?

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 create a list in workflow and send it back to the Silverlight grid?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Oo萌小芽oO 2024-10-07 08:36:45

只需从工作流服务返回一个列表,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<Student>" sap:VirtualizedContainerService.HintSize="257,100" Item="[New Student() With {.ID = item, .Name = "Student " & 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>

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

The workflow
alt text

The Silverlight client

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

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<Student>" sap:VirtualizedContainerService.HintSize="257,100" Item="[New Student() With {.ID = item, .Name = "Student " & 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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文