WF instance learning notes: (2) using workflow to call WCF data services to obtain data

Source: Internet
Author: User

Effect of running the program homepage:

First open the homecontroller. CS File

        public ActionResult Index()        {            #region XAML            //var activity =            //    ActivityXamlServices.Load(            //    Server.MapPath("~/workflows/GetDataForMainPage.xaml"));            //var results = WorkflowInvoker.Invoke(activity);            #endregion            var results =                WorkflowInvoker.Invoke(                new CustomActivities.GetDataForMainPage());            ViewData["candidates"] = results["candidates"];            ViewData["workOrders"] = results["workOrders"];            return View();        }

The program uses workflowinvoker. invoke to call the getdataformainpage activity and save the returned results in viewdata.
Analyze the getdataformainpage Activity

A parallel workflow contains two getodata activities. The returned results of a generic activity, ienumerable <jobcandidate> and ienumerable <workorder>, are bound to the output parameters candidate and workorders.

Next, let's look at the implementation of getodata.

    public sealed class GetOData<T> : AsyncCodeActivity<IEnumerable<T>>    {        [RequiredArgument]        public InArgument<Uri> ServiceUrl { get; set; }        public InArgument<string> EntitySetName { get; set; }        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context,             AsyncCallback callback, object state)        {             DataServiceContext ctx =                new DataServiceContext(ServiceUrl.Get(context));           DataServiceQuery<T> query = ctx.CreateQuery<T>(EntitySetName.Get(context));           context.UserState = query;           return query.BeginExecute(callback, state);        }        protected override IEnumerable<T> EndExecute(AsyncCodeActivityContext context, IAsyncResult result)        {            DataServiceQuery<T> query = context.UserState as DataServiceQuery<T>;            return query.EndExecute(result);        }            }

The code in this section calls WCF data services through asynchronous dataservicequery.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.