我有以下调用网络服务的方法。DownloadStringCompletedEventHandler 'callback' 显然是该函数完成后将流向的函数控制:
private void myWebService(string yourParameter, DownloadStringCompletedEventHandler callback)
{
//Url to search servlet
string servletUrl = string.Format("https://something.com/etc/what?bla={0}",
Uri.EscapeDataString(yourParameter));
//Calls Servlet
WebClient client = new WebClient();
client.DownloadStringCompleted += callback;
client.DownloadStringAsync(new Uri(servletUrl, UriKind.Absolute));
}
我这样调用上面的函数:
myWebService("Hello there!", myWebServiceReturn);
WebServiceReturn(控制将在 web 服务调用之后结束)看起来像这样:
private void myWebServiceReturn(object sender, DownloadStringCompletedEventArgs e)
{
//And here we end up...
//how do I get the value of 'yourParameter' that I sent to 'myWebService()'??
}
所以我的问题是.. 我发送到“myWebService()”的参数,在本例中是“yourParameter”,如何在“myWebServiceReturn”方法中获得相同的值?如果我能以某种方式将其附加到“DownloadStringCompletedEventArgs e”并以这种方式检索它,那将非常方便。
真的很感谢任何人的帮助!:(