Asynchronous webservice call. No (Begin…) method available?

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.

Up vote 1 down vote favorite share g+ share fb share tw.

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 " } } 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 Begin 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 don't I get the BeginHello method & Why do I get this error as above?

Thanks for your time. C# .net asynchronous webservice-client link|improve this question asked Oct 14 '10 at 11:00user203581,4552932 74% accept rate.

Please show us the whole class (both the callback and the method that calls the webservice) – jgauffin Oct 14 '10 at 11:06 @user20358 - I updated my answer. – Kev? Oct 14 '10 at 11:51 @user20358 - see my latest update.

– Kev? Oct 14 '10 at 13:39.

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: 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.

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.

Thanks. That solved one problem. What about the missing Begin – user20358 Oct 14 '10 at 11:19 Thanks Kev.

So you're saying that ASP. NET 2.0 onwards they removed the {Begin...} prefix to async calls? – user20358 Oct 14 '10 at 12:18 I don't think this line will work: my.

HelloCompleted += CallBack; I will add an aswer shwoing what I did that got it working. Meanwhile how does this guy have both methods available? Codeproject.com/Articles/70441/… – user20358 Oct 14 '10 at 12:19.

Here is what I changed on the client side to get it working. Static void Main(string args) { MyService my = new MyService(); my. HelloCompleted +=new HelloCompletedEventHandler(my_HelloCompleted); my.HelloAsync(); Console.

WriteLine("Called webservice"); Console.ReadKey(); } private static void my_HelloCompleted(object sender, HelloCompletedEventArgs e) { Console. Write("Webservice finished executing in my_HelloCompleted. "); }.

Glad you got it working. :) From C#2.0 onwards you don't need to specify the new HelloCompletedEventHandler. Just do: my.

HelloCompleted += my_HelloCompleted. – Kev? Oct 15 '10 at 12:13 Thanks Kev.

Will try that out. :) – user20358 Oct 19 '10 at 11:30.

Here is what I changed on the client side to get it working.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions