I know this has been examined before, but I have a service that returns such a string.
[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 read a lot of examples that say that I need to call a method as follows:
MyService my = new MyService(); AsyncCallback async = new AsyncCallback(callback); my.BeginHello(); Console.WriteLine("Called webservice");
The fact is that when I added the link, I did not get the BeginHello method. All I saw is HelloAsync. Therefore, I used it in my console application.
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 message:
An object reference is required for a non-static field, method or property "AsyncWebserviceCall.Program.callback (System.IAsyncResult)
Why didn’t I get the BeginHello method and why did I get this error as above?
Thank you for your time.
source share