VS 2k13
.NET 4.5
At the time of adding web service reference, I clicked on advanced and opted in to generate async operations as shown here :
http://techybit.com/wp-content/uploads/2011/08/image3.png
I am getting an exception on line # 29
An exception of type 'System.ArgumentException' occurred in mscorlib.dll but was not handled in user code
Additional information: Async End called with an IAsyncResult from a different Begin method.
Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ConsoleApplication2.ServiceReference1;
namespace ConsoleApplication2
{
class Program
{
//address : http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL
static void Main(string[] args)
{
string zip = "60601";
ServiceReference1.WeatherSoapClient client = new WeatherSoapClient("WeatherSoap");
AsyncCallback cb = new AsyncCallback(Program.GetWeatherByZipCodeCallback);
IAsyncResult ar = client.BeginGetCityWeatherByZIP(zip, cb, client);
Console.WriteLine("Getting Data ...");
while (!ar.IsCompleted);
Console.ReadKey();
}
public static void GetWeatherByZipCodeCallback(IAsyncResult ar)
{
Console.Clear();
WeatherSoapClient client = (WeatherSoapClient)ar.AsyncState;
ForecastReturn result = client.EndGetCityForecastByZIP(ar); // here
Console.WriteLine(result.City);
}
}
}
reference : MSDN man page
No comments:
Post a Comment