In this blog post we are going to see how we can covert asynchronous method call to Task by using Task.Factory.FromAsync method.
For this example I am going to call the following Web service to get the weather information for given Zip code.
when adding this above Web Service Reference we need to check Generate asynchronous Operations. so that VS.NET will generate Async method calls.
First Create Instance of the web service Proxy. and Create the Task with Begin and End methods which you are going to invoke on Web Service. Basically this web service takes input as Zip code and returns as 1 week Weather forecast info .
Here is the weather result for the Zipcode =75023
suppose Web service response is null then I can canceling the task . here is the result for unknown zip code.
Here I am scheduling a continuation task once we get the response from Web Service. I feel this way of calling Web Service is more convenient than an IAsyncResult.
Nandri(Thanks)
SreenivasaRagavan.
No comments:
Post a Comment