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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:33:40+00:00 2026-05-17T16:33:40+00:00

I know this has been addressed before but I have service that returns a

  • 0

I know this has been addressed before but I have service that returns a string like so.

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class MyService : System.Web.Services.WebService
{

    [WebMethod]
    public string Hello()
    {
        System.Threading.Thread.Sleep(10000);
        return "Hello User";
    }
}

I’ve read many examples that say I need to call the method like this:

        MyService my = new MyService();
        AsyncCallback async = new AsyncCallback(callback);
        my.BeginHello();
        Console.WriteLine("Called webservice");

The thing is when I added reference I coudn’t get the BeginHello method. All I saw was the HelloAsync. So I used it like this in my console app.

        MyService my = new MyService();
        AsyncCallback async = new AsyncCallback(callback);
        my.HelloAsync();
        Console.WriteLine("Called webservice");

and defined a private callback method like this

    private void callback(IAsyncResult res)
    {
        Console.Write("Webservice finished executing.");
    }

In doing so, I get an error like this:

An object reference is required for
the non-static field, method, or
property
‘AsyncWebserviceCall.Program.callback(System.IAsyncResult)

Why dont I get the BeginHello method & Why do I get this error as above?

Thanks for your time.

  • 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-17T16:33:41+00:00Added an answer on May 17, 2026 at 4:33 pm

    If the code is being run inside your public static void Main(string[] args) function then you need to make private void callback(IAsyncResult res) a static method:

    private static void callback(IAsyncResult res)
    {
        Console.Write("Webservice finished executing.");
    }
    

    That’s why you’re getting that error.

    From ASP.NET 2.0 onwards there were some changes to how you make async web service calls. Do this instead:

    MyService my = new MyService();
    my.HelloCompleted += CallBack;
    my.HelloAsync();
    Console.WriteLine("Called service.");
    Console.ReadLine();  // Wait, otherwise console app will just exit.
    

    Your callback method signature changes to:

    private static void CallBack(object sender, HelloCompletedEventArgs e)
    {
        Console.WriteLine("Webservice finished executing.");
    }
    

    More info:

    From Visual Studio 2005 onwards the Add Web Reference proxy generator no longer creates the BeginXXX/EndXXX methods. These methods were deprecated in favour of the XXXAsync/XXXCompleted pattern.

    If you really need to work with the BeginXXX/EndXXX style async methods you can use one of the following methods:

    1. Use the WSDL.exe tool to create the proxy. For example:

      wsdl.exe /out:MyService.cs http://somedomain.com/MyService.asmx?wdsl

      Include the generated MyService.cs file in your project and use that instead of a Web Reference. You need to open a Visual Studio command prompt for this so that the .NET Framework SDK binaries are in your path.

    2. There is apparently a hack in Visual Studio (it may no longer be available). For more info see this MS Connect case:

    Begin/End Async WebService Proxy Methods Not Generated in Web Application Projects

    My advice would be to embrace the new approach.

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

Sidebar

Related Questions

I know this issue has been addressed before but I have not found an
I know something like this has been asked before, but the answer was sort
I know that this has been discused before but i cant find an answer..
ok, I know that this topic has been addressed several times on here, but
I know this question has been asked before but I seem to have a
I know this has been asked many times before, but i still can't seem
I know this has been asked before but all the answers I found didn't
I know this has been asked much the same before but no answers seem
I know this has been asked before, but I just cant seem to find
I know this might have been asked a thousand times before, but I can't

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.