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

  • SEARCH
  • Home
  • 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 6356429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:57:35+00:00 2026-05-24T22:57:35+00:00

In Silverlight 4, all WCF calls made from the UI thread must be asynchronous.

  • 0

In Silverlight 4, all WCF calls made from the UI thread must be asynchronous. This is fine. The WCF client code exposes methods and events like

void GetDataAsync(SomeArgument a);
event EventHandler<GetDataCompletedEventArgs> GetDataCompleted;

Is it possible to wrap it or configure WCF/Silverlight to generate the following?

void GetDataAsync(SomeArgument a, EventHandler<GetDataCompletedEventArgs>);

In my project I created a class responsible for all method calls, that is accessable to higher layers (like view model). It exposes methods like:

void GetData(SomeArgument a, Action<SomeResult> callback);

Now the serviceClient is reusable, so I need to unsubscribe from the *Completed event after the call is finished. My best approach so far is this:

EventHandler<T> MakeHandler<T>(Action<T> callback) where T : AsyncCompletedEventArgs
{
    return (sender, eventArgs) =>
    {
        callback(eventArgs); // perform some operations in view model
        ((Action)eventArgs.UserState)(); // this is to unsubscribe from event
    };
}

void GetData(SomeArgument a, Action<SomeResult> callback)
{
    var handler = MakeHandler<GetDataCompletedEventArgs>((s, ea) => callback(ea.Result));
    serviceClient.GetDataCompleted += handler
    serviceClient.GetDataAsync(a, new Action(() => serviceClient.GetDataCompleted -= handler));
}

I’d really like to avoid having to retype the whole GetData() wiring for every used WCF method and just do something like:

void GetData(SomeArgument a, Action<SomeResult> callback)
{
    serviceClient.GetDataAsync(a, callback);
}
  • 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-24T22:57:36+00:00Added an answer on May 24, 2026 at 10:57 pm

    You can access the Begin/End “.NET Async Pattern” for your WCF service by using the Service interface of the ServiceClient. For example if you have a WCF service called “Service1” your Silverlight project will contain a “Service1Client” class (that uses the Async/Event pattern to expose operations) but it also explicitly implements an interface called “Service1” which uses the Begin/End pair for each operation. Use:-

    Service1 service = new Service1Client();
    

    Now with access to the Begin/End pair things get a little easier. You can use the following Generic function to create the basic plumbing to calling the Async pattern:

        public static Action<Action<T>, Action<Exception>> AsyncExecute<T>(Action<AsyncCallback> begin, Func<IAsyncResult, T> end)
        {
            return (success, fail) =>
            {
                AsyncCallback cb = (ar) =>
                {
                    try
                    {
                        success(end(ar));
                    }
                    catch (Exception err)
                    {
                        fail(err);
                    }
                };
    
                begin(cb);
            };
        }
    

    You can consume it with a specific function:

     void GetData(SomeArgument a, Action<SomeResult> success)
     {
          var fn = AsyncExecute<SomeResult>(cb => service.BeginGetData(a, cb, null), service.EndGetData);
          fn(success, GeneralFail);
     }
    
     public static void GeneralFail(Exception err)
     {
          // General reporting of fail
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm calling a WCF service from a Silverlight client, therefore making all the calls
I make calls to a WCF service from my silverlight application. I am doing
I'm trying to write a class that encapsulates WCF calls (the client is Silverlight,
What's all this business about Flash, Flex, Adobe Air, Java FX and Silverlight? Why
I have Silverlight application that retrieves data from the database through a WCF Service.
I am consuming WCF services from a Silverlight application (MVVM) and windows phone. I
I forked from thread When using MVVM pattern, should code relating to property changes
I have a WCF service (not RIA) that I access from Silverlight. The application
SILVERLIGHT IS Not SAFE (privacy) We developed project with silverlight + wcf. We all
I´m deploying a small Silverlight application, which consumes data from a WCF DataService then

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.