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.