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 9065719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:34:35+00:00 2026-06-16T16:34:35+00:00

I have a webservice written in Yii (php framework). I use C# and Visual

  • 0

I have a webservice written in Yii (php framework).

I use C# and Visual Studio 2012 to develop a WP8 application. I added a service reference to my project (Add Service Reference). So I am able to use webservice functions.

   client = new YChatWebService.WebServiceControllerPortTypeClient();

   client.loginCompleted += client_loginCompleted;   // this.token = e.Result;
   client.loginAsync(this.username, this.password); 

   client.getTestCompleted += client_getTestCompleted;
   client.getTestAsync(this.token); 

function getTestAsync and loginAsync return void and both are asynchronous. Is it possible for the functions to return Task<T>? I would like to use async/await keywords in my program.

  • 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-06-16T16:34:36+00:00Added an answer on June 16, 2026 at 4:34 pm

    Assuming that loginAsync returns void, and loginCmpleted event fires when login is done, this is called the Event-based Asynchronous Pattern, or EAP.

    To convert EAP to await/async, consult Tasks and the Event-based Asynchronous Pattern. In particular, you’ll want to make use of the TaskCompletionSource to convert the event-based model to a Task-based model. Once you’ve got a Task-based model, you can use C# 5’s sexy await feature.

    Here’s an example:

    // Use LoginCompletedEventArgs, or whatever type you need out of the .loginCompleted event
    // This is an extension method, and needs to be placed in a static class.
    public static Task<LoginCompletedEventArgs> LoginAsyncTask(this YChatWebService.WebServiceControllerPortTypeClient client, string userName, string password) 
    { 
        var tcs = CreateSource<LoginCompletedEventArgs>(null); 
        client.loginCompleted += (sender, e) => TransferCompletion(tcs, e, () => e, null); 
        client.loginAsync(userName, password);
        return tcs.Task; 
    }
    
    private static TaskCompletionSource<T> CreateSource<T>(object state) 
    { 
        return new TaskCompletionSource<T>( 
            state, TaskCreationOptions.None); 
    }
    
    private static void TransferCompletion<T>( 
        TaskCompletionSource<T> tcs, AsyncCompletedEventArgs e, 
        Func<T> getResult, Action unregisterHandler) 
    { 
        if (e.UserState == tcs) 
        { 
            if (e.Cancelled) tcs.TrySetCanceled(); 
            else if (e.Error != null) tcs.TrySetException(e.Error); 
            else tcs.TrySetResult(getResult()); 
            if (unregisterHandler != null) unregisterHandler();
        } 
    }
    

    Now that you’ve converted the Event-based async programming model to a Task-based one, you can now use await:

    var client = new YChatWebService.WebServiceControllerPortTypeClient();
    var login = await client.LoginAsyncTask("myUserName", "myPassword");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WCF-Service, written in Visual Basic using Visual Studio 2010. I would
I have C# Client application calling Windows webservice written in WCF calling Sql Procedure
I have written a webservice using the PHP SOAP classes. It has functions to
I have a webservice and ios application. I use ASIHTTPRequest.h, ASIFormDataRequest.h headers to handle
I have Written a webservice with VS2008 after I had Added Reference to that
Below i have written code of a soap webservice in php with its client,It
I have a webservice, written in PHP, which I want to consume in a
Background: I have a winform application written in VB.NET that uses a WebService to
i have an application written in Play Framework 1.2.5 and i am using H2
I have written an ASMX service that looks like thus; namespace AtomicService { [WebService(Namespace

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.