Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6570659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:47:00+00:00 2026-05-25T14:47:00+00:00

I have a few WCF calls, lets say A, B, C, D, E. They

  • 0

I have a few WCF calls, lets say A, B, C, D, E. They are in a SL application (so I guess I have to be careful with threading and such).
I want B to run after A has completed, while C can run concurrent with them. I want D to run after all three of them finished. And additionally based on a condition (simple if…) I want E to run too (concurrent with any of the above).

I just downloaded Rx and feel that it is the tool for this job. However I don’t yet grasp all the operators and the tricks and such.

Can this be done? How? Please explain the operators required for this.

EDIT to add: For simplicity’s sake let’s say all of these services take a string (or an int) as a parameter, and returns something which implements a complex interface, so the events are simple EventHandlers (non-generic), and I cast them to their special interface in the handler code.
Some inputs are available at the start, some come from result of previous services (e.g. B’s input string is computed based on A’s result)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:47:00+00:00Added an answer on May 25, 2026 at 2:47 pm

    I’ve taken the edit into account and put together a solution.

    I do have to say that Microsoft has made it awfully hard to write simple WCF calls in Silverlight. Handling events to get the return data from async calls is just painful.

    Having said that, with a little bit of “copy-and-paste” boiler-plate code, Rx does a great job of removing the complexity.

    Here’s what I came up with as the final client code:

            var service = new Service1Client();
    
            var abs =
                from a in service.AObservable("a")
                from b in service.BObservable(a)
                select new { a, b };
    
            var cs = service.CObservable("c");
    
            var abcs = abs.Zip(cs, (ab, c) => new { ab.a, ab.b, c });
    
            var ds =
                from abc in abcs
                from d in service.DObservable(abc.a, abc.b, abc.c)
                select String.Format(
                    "A={0} B={1} C={2} D={3}",
                    abc.a, abc.b, abc.c, d);
    
            var condition = true;
    
            var es = from e in condition
                        ? service.EObservable("e")
                        : Observable.Empty<string>()
                     select String.Format("E={0}", e);
    
            ds.Merge(es).ObserveOnDispatcher()
                        .Subscribe(r => this.label1.Content += " " + r);
    

    On one hand this code isn’t as pretty as I had hoped, but on the other I don’t think I could get it any better. Hopefully you can see how your requirements are being met.

    Now for the bad news – the extension methods must be created for every service proxy. The way the EventArgs are defined there is no way to get the results out without using the specific service reference class as the this parameter for the extension methods.

    On the plus side though the code is mostly “copy-and-paste” with very little modification.

    Also, you do need to create as many extension methods as many parameters you use plus one.

    Here are the extension methods I needed to define for my sample code:

    public static class Service1ClientEx
    {
        public static Func<IObservable<R>> ToObservableFunc<EA, R>(this Service1Client service, Action<Service1Client> async, Action<Service1Client, EventHandler<EA>> ah, Action<Service1Client, EventHandler<EA>> rh, Func<EA, R> resultSelector)
            where EA : System.ComponentModel.AsyncCompletedEventArgs
        {
            return () => Observable.Create<R>(o =>
            {
                var response =
                    from ep in Observable.FromEventPattern<EA>(h => ah(service, h), h => rh(service, h))
                    select resultSelector(ep.EventArgs);
    
                var subscription = response.Take(1).Subscribe(o);
    
                async(service);
    
                return subscription;
            }).ObserveOn(Scheduler.ThreadPool);
        }
    
        public static Func<P0, IObservable<R>> ToObservableFunc<P0, EA, R>(this Service1Client service, Action<Service1Client, P0> async, Action<Service1Client, EventHandler<EA>> ah, Action<Service1Client, EventHandler<EA>> rh, Func<EA, R> resultSelector)
            where EA : System.ComponentModel.AsyncCompletedEventArgs
        {
            return p0 => Observable.Create<R>(o =>
            {
                var response =
                    from ep in Observable.FromEventPattern<EA>(h => ah(service, h), h => rh(service, h))
                    select resultSelector(ep.EventArgs);
    
                var subscription = response.Take(1).Subscribe(o);
    
                async(service, p0);
    
                return subscription;
            }).ObserveOn(Scheduler.ThreadPool);
        }
    
        public static Func<P0, P1, IObservable<R>> ToObservableFunc<P0, P1, EA, R>(this Service1Client service, Action<Service1Client, P0, P1> async, Action<Service1Client, EventHandler<EA>> ah, Action<Service1Client, EventHandler<EA>> rh, Func<EA, R> resultSelector)
            where EA : System.ComponentModel.AsyncCompletedEventArgs
        {
            return (p0, p1) => Observable.Create<R>(o =>
            {
                var response =
                    from ep in Observable.FromEventPattern<EA>(h => ah(service, h), h => rh(service, h))
                    select resultSelector(ep.EventArgs);
    
                var subscription = response.Take(1).Subscribe(o);
    
                async(service, p0, p1);
    
                return subscription;
            }).ObserveOn(Scheduler.ThreadPool);
        }
    
        public static Func<P0, P1, P2, IObservable<R>> ToObservableFunc<P0, P1, P2, EA, R>(this Service1Client service, Action<Service1Client, P0, P1, P2> async, Action<Service1Client, EventHandler<EA>> ah, Action<Service1Client, EventHandler<EA>> rh, Func<EA, R> resultSelector)
            where EA : System.ComponentModel.AsyncCompletedEventArgs
        {
            return (p0, p1, p2) => Observable.Create<R>(o =>
            {
                var response =
                    from ep in Observable.FromEventPattern<EA>(h => ah(service, h), h => rh(service, h))
                    select resultSelector(ep.EventArgs);
    
                var subscription = response.Take(1).Subscribe(o);
    
                async(service, p0, p1, p2);
    
                return subscription;
            }).ObserveOn(Scheduler.ThreadPool);
        }
    
        public static Func<P0, P1, P2, P3, IObservable<R>> ToObservableFunc<P0, P1, P2, P3, EA, R>(this Service1Client service, Action<Service1Client, P0, P1, P2, P3> async, Action<Service1Client, EventHandler<EA>> ah, Action<Service1Client, EventHandler<EA>> rh, Func<EA, R> resultSelector)
            where EA : System.ComponentModel.AsyncCompletedEventArgs
        {
            return (p0, p1, p2, p3) => Observable.Create<R>(o =>
            {
                var response =
                    from ep in Observable.FromEventPattern<EA>(h => ah(service, h), h => rh(service, h))
                    select resultSelector(ep.EventArgs);
    
                var subscription = response.Take(1).Subscribe(o);
    
                async(service, p0, p1, p2, p3);
    
                return subscription;
            }).ObserveOn(Scheduler.ThreadPool);
        }
    
        public static IObservable<string> AObservable(this Service1Client service, string data)
        {
            return service
                .ToObservableFunc<string, ACompletedEventArgs, string>((s, p0) => s.AAsync(p0), (s, h) => s.ACompleted += h, (s, h) => s.ACompleted -= h, ea => ea.Result)
                .Invoke(data);
        }
    
        public static IObservable<string> BObservable(this Service1Client service, string data)
        {
            return service
                .ToObservableFunc<string, BCompletedEventArgs, string>((s, p0) => s.BAsync(p0), (s, h) => s.BCompleted += h, (s, h) => s.BCompleted -= h, ea => ea.Result)
                .Invoke(data);
        }
    
        public static IObservable<string> CObservable(this Service1Client service, string data)
        {
            return service
                .ToObservableFunc<string, CCompletedEventArgs, string>((s, p0) => s.CAsync(p0), (s, h) => s.CCompleted += h, (s, h) => s.CCompleted -= h, ea => ea.Result)
                .Invoke(data);
        }
    
        public static IObservable<string> DObservable(this Service1Client service, string dataA, string dataB, string dataC)
        {
            return service
                .ToObservableFunc<string, string, string, DCompletedEventArgs, string>((s, p0, p1, p2) => s.DAsync(p0, p1, p2), (s, h) => s.DCompleted += h, (s, h) => s.DCompleted -= h, ea => ea.Result)
                .Invoke(dataA, dataB, dataC);
        }
    
        public static IObservable<string> EObservable(this Service1Client service, string data)
        {
            return service
                .ToObservableFunc<string, ECompletedEventArgs, string>((s, p0) => s.EAsync(p0), (s, h) => s.ECompleted += h, (s, h) => s.ECompleted -= h, ea => ea.Result)
                .Invoke(data);
        }
    }
    

    Like I said, painful.

    You certainly don’t have to create these type of extension methods to use Rx with WCF in Silverlight, but it’s my feeling that once you have created them then the client code becomes much, much easier to work with.

    Let me know if you need more explanation on anything.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the problem: I have a WCF service and a few sites connecting
I have few nested DIVs at page. I want to add event only for
I have to create an application that will be started a few times per
I have a web application that is talking to a WCF service hosted within
I have WCF web service and client that calls this service, This client will
I'm fairly new to WCF development and have run into a couple problems whilst
I have a WCF service that has a few different responsibilities, but it provides
I have a WCF client which passes Self-Tracking Entities to a WPF application built
I have a .NET application with a web front-end, WCF Windows service back-end. The
I have few asynchronous tasks running and I need to wait until at least

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.