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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:46:34+00:00 2026-06-15T14:46:34+00:00

My OperationContract : public List<MessageDTO> GetMessages() { List<MessageDTO> messages = new List<MessageDTO>(); foreach (Message

  • 0

My OperationContract:

public List<MessageDTO> GetMessages()
        {
            List<MessageDTO> messages = new List<MessageDTO>();
            foreach (Message m in _context.Messages.ToList())
            {
                messages.Add(new MessageDTO()
                {
                    MessageID = m.MessageID,
                    Content = m.Content,
                    Date = m.Date,
                    HasAttachments = m.HasAttachments,
                    MailingListID = (int)m.MailingListID,
                    SenderID = (int)m.SenderID,
                    Subject = m.Subject
                });
            }
            return messages;
        }

In Service Reference configuration I checked the option “Generate asynchronous operations”. How do I use the generated GetMessagesAsync()? In the net I found examples that use AsyncCallback, however I’m not familiar with that. Is there a way to use it in some friendly way like async and await keywords in .NET 4.5? If not, what should I do to invoke the method asynchronously?

  • 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-15T14:46:35+00:00Added an answer on June 15, 2026 at 2:46 pm

    If you select ‘Generate asynchrounous operations’, you will get the ‘old’ behavior where you have to use callbacks.

    If you want to use the new async/await syntax, you will have to select ‘Generate task-based operations’ (which is selected by default).

    When using the default Wcf template, this will generate the following proxy code:

      public System.Threading.Tasks.Task<string> GetDataAsync(int value) {
          return base.Channel.GetDataAsync(value);
      }
    

    As you can see, there are no more callbacks. Instead a Task<T> is returned.

    You can use this proxy in the following way:

    public static async Task Foo()
    {
        using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
        {
            Task<string> t = client.GetDataAsync(1);
            string result = await t;
        }
    }
    

    You should mark the calling method with async and then use await when calling your service method.

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

Sidebar

Related Questions

public class Service1 : IService1 { [OperationContract] public List<decmal> GetEnterCounts(DateTime StartTime, DateTime EndTime) {
I am using WCF DataService I have a method: [OperationContract] public List<string> GetAges() {
The following Server-Side code works: [OperationContract] public IEnumerable<object> GetBooks() { var people = new
The simple case where my OperationContract implementation is like: public List<Directory> GetDirectories(bool includeFiles) {
ServiceContract [OperationContract] List<Campaign> AttainCampaigns(); Works when Instantiating Objects Directly public List<Campaign> AttainCampaigns() { var
My Service Contract [ServiceContract] public interface ITsdxService { [OperationContract] [WebGet(UriTemplate=/GetTestCostCentre)] CostCentre GetTestCostCentre(); [OperationContract] [WebInvoke(UriTemplate=/SetCostCentre,
I have defined the following Interface [ServiceContract] public interface IHealthProducts { [OperationContract()] ResponseClass OrderSelfSignedHealthCertificate();
I have created the simple web service. Code: [ServiceContract] public interface ITsdxService { [OperationContract]
I have the following: [ServiceContract] [ServiceKnownType(typeof(ActionParameters))] [ServiceKnownType(typeof(SportProgram))] [ServiceKnownType(typeof(ActionResult<SportProgram>))] public interface ISportProgramBl { [OperationContract] IActionResult<ISportProgram>
I have an AJAX-enabled WCF service with the following signature: [OperationContract] [WebGet] public JQGridContract

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.