confusion over asynchronous methods inside web service
-
Hi there, I have been looking into implementing Asynchronous programming model within my webservice and my asp.net web form. I have found a few good MSDN articles, [^], to achieve this but there is one thing I do not quite follow. My webservice code is as listed below. I add all the relevant code including a web reference to my HelloWorldWebService in my asp.net web form to utilise PageAsyncTask functionality. One thing I have noticed is that when I create an instance of the HelloWorldWebService web service, it does not display the BeginHelloWorldProcedure and EndHelloWorldProcedure methods and the only asynchronous method HelloWorldProcedureAsync is displayed My questions are: 1) why am not seeing BeginHelloWorldProcedure and EndHelloWorldProcedure methods ? 2)If I am supposed to use HelloWorldProcedureAsync method how does this supply the IAsyncResult which is the output of BeginEventHandlder part of the input of PageAsyncTask Any help will be appreciated. thanks.
[WebService] public class HelloWorldWebService : System.Web.Services.WebService { public delegate string HelloWorldAsyncStub(); public string HelloWorldProcedure() { return "HelloWorld"; } public class MyState { public object previousState; public HelloWorldAsyncStub helloworldStubStub; } [System.Web.Services.WebMethod] public IAsyncResult BeginHelloWorldProcedure(AsyncCallback cb, object s) { HelloWorldAsyncStub stub = new HelloWorldAsyncStub(HelloWorldProcedure); MyState ms = new MyState(); ms.previousState = s; ms.helloworldStubStub = stub; return stub.BeginInvoke(cb, ms); } [System.Web.Services.WebMethod] public string EndHelloWorldProcedure(IAsyncResult call) { MyState ms = (MyState)call.AsyncState; return ms.helloworldStubStub.EndInvoke(call); } }
-
Hi there, I have been looking into implementing Asynchronous programming model within my webservice and my asp.net web form. I have found a few good MSDN articles, [^], to achieve this but there is one thing I do not quite follow. My webservice code is as listed below. I add all the relevant code including a web reference to my HelloWorldWebService in my asp.net web form to utilise PageAsyncTask functionality. One thing I have noticed is that when I create an instance of the HelloWorldWebService web service, it does not display the BeginHelloWorldProcedure and EndHelloWorldProcedure methods and the only asynchronous method HelloWorldProcedureAsync is displayed My questions are: 1) why am not seeing BeginHelloWorldProcedure and EndHelloWorldProcedure methods ? 2)If I am supposed to use HelloWorldProcedureAsync method how does this supply the IAsyncResult which is the output of BeginEventHandlder part of the input of PageAsyncTask Any help will be appreciated. thanks.
[WebService] public class HelloWorldWebService : System.Web.Services.WebService { public delegate string HelloWorldAsyncStub(); public string HelloWorldProcedure() { return "HelloWorld"; } public class MyState { public object previousState; public HelloWorldAsyncStub helloworldStubStub; } [System.Web.Services.WebMethod] public IAsyncResult BeginHelloWorldProcedure(AsyncCallback cb, object s) { HelloWorldAsyncStub stub = new HelloWorldAsyncStub(HelloWorldProcedure); MyState ms = new MyState(); ms.previousState = s; ms.helloworldStubStub = stub; return stub.BeginInvoke(cb, ms); } [System.Web.Services.WebMethod] public string EndHelloWorldProcedure(IAsyncResult call) { MyState ms = (MyState)call.AsyncState; return ms.helloworldStubStub.EndInvoke(call); } }
Hi Ekynox,
ekynox wrote:
- why am not seeing BeginHelloWorldProcedure and EndHelloWorldProcedure methods ?
I used the above code created a WebSevice in VB (as Language does not matter). And I am able to see the Begin and End of the Web method in my website where I implemented. Could you please tell me how you implemented it in your application?
[Venkatesh Mookkan] My: Website | Yahoo Group | Blog Spot
-
Hi Ekynox,
ekynox wrote:
- why am not seeing BeginHelloWorldProcedure and EndHelloWorldProcedure methods ?
I used the above code created a WebSevice in VB (as Language does not matter). And I am able to see the Begin and End of the Web method in my website where I implemented. Could you please tell me how you implemented it in your application?
[Venkatesh Mookkan] My: Website | Yahoo Group | Blog Spot
Hi there, Thanks for the response. I actually worked out why I was not seeing the BeginXXX/EndXXX methods. When I complied the code under VS 2005, the compiler will automatically generate the BeginXXX/EndXXX methods of each web method found in your webservice. However, if you use VS 2008 .NET3.5 based web service the BeginXXX/EndXXX methods for each web method is not generated even if you explicitly state your BeginXXX/EndXXX methods it still wont be shown under VS 2008 .NET3.5. It would be interesting to findout why under VS 2008 and .NET 3.5 does this happen. In order to work around this I have decided not to bother with PageAsyncTask and just use the Async version of my web method. cheers