asp.net无法异步调用WebService
public void ChangeProcessBar(){
for (int i = 0; i < 10; i++)
{
this.Label1.Text = DateTime.Now.ToString();
System.Threading.Thread.Sleep(500);
}
}
private void AsynCall_In_WebServiceProxy()
{
ProductService.LTPService ws = new WebService.ProductService.LTPService(); // Web Service代理类
ws.GetClass1Completed += new ProductService.GetClass1CompletedEventHandler(s_GetClass1Completed);// 注册调用完成后的回调方法
ws.GetClass1Async(3000); // 这里开始异步调用
ChangeProcessBar();// 调用同时客户端处理不停止
}
private void s_GetClass1Completed(object sender, ProductService.GetClass1CompletedEventArgs e)
{
if (e.Error != null)
throw e.Error;
this.Label1.Text = "完成!"; // 调用完成了,把客户端进度条填充满
ProductService.People people = e.Result as ProductService.People; // 结果转化为Class1对象
Response.Write("ID is " + (people.PId.ToString() + ",Name is " + people.Name + ",Pwd id" + people.Pwd)); //显示从服务器获取的对象值
}
protected void Button1_Click(object sender, EventArgs e)
{
//AsyncCall_In_Backgroundworker();
}
protected void Button2_Click(object sender, EventArgs e)
{
AsynCall_In_WebServiceProxy();
}
这里总是等调用WebService方法完成后再调用ChangeProcessBar(),可是在WinForm中可以正常异步调用,我已经设置了Async="true",用的是vs2008 --------------------编程问答-------------------- 我混乱了,从目前代码来看,就算你GetClass1Async异步了也看不出效果来。
for (int i = 0; i < 10; i++)
{
this.Label1.Text = DateTime.Now.ToString();
System.Threading.Thread.Sleep(500);
}
这个在客户端来看,只有最后一次的结果。
asp.net 应用Response只有一次 --------------------编程问答-------------------- 是的。。难道只能用进度条的方式吗 --------------------编程问答-------------------- 是的,只能用 ajax 方式。 --------------------编程问答-------------------- ajax get post 异步吧
补充:.NET技术 , Web Services